buffering

How do I simulate a buffered peripheral device with SwingWorker?

一个人想着一个人 提交于 2019-11-26 11:56:11
I'm using this exercise as a pedagogical tool to help me burn in some Java GUI programming concepts. What I'm looking for is a general understanding, rather than a detailed solution to one specific problem. I expect that coding this "right" will teach me a lot about how to approach future multi-threaded problems. If this is too general for this forum, possibly it belongs in Programmers? I'm simulating a card reader. It has a GUI, allowing us to load cards into the hopper and press Start and so forth, but its main "client" is the CPU, running on a separate thread and requesting cards. The card

PHP CLI: How to read a single character of input from the TTY (without waiting for the enter key)?

感情迁移 提交于 2019-11-26 09:30:50
问题 I want to read a single character at-a-time from the command line in PHP, however it seems as though there is some kind of input buffering from somewhere preventing this. Consider this code: #!/usr/bin/php <?php echo \"input# \"; while ($c = fread(STDIN, 1)) { echo \"Read from STDIN: \" . $c . \"\\ninput# \"; } ?> Typing in \"foo\" as the input (and pressing enter), the output I am getting is: input# foo Read from STDIN: f input# Read from STDIN: o input# Read from STDIN: o input# Read from

Wrong IO actions order using putStr and getLine

帅比萌擦擦* 提交于 2019-11-26 07:38:07
问题 I have the following code: main = do putStr \"Test input : \" content <- getLine putStrLn content When I run it (with runhaskell ) or compile it (ghc 6.10.4) the result is like this: asd Test input : asd Why is Test input : asd being printed after asd ? In the code sample on http://learnyouahaskell.com/, which uses putStr , the getLine \'s presented output is different than mine. When I use putStrLn the program works as expected (print, then prompt, and print). Is it a bug in ghc , or it is

Buffered vs unbuffered IO

懵懂的女人 提交于 2019-11-26 04:59:53
问题 I learned that by default I/O in programs is buffered, i.e they are served from a temporary storage to the requesting program. I understand that buffering improves IO performance (maybe by reducing system calls). I have seen examples of disabling buffering, like setvbuf in C. What is the difference between the two modes and when should one be used over the other? 回答1: You want unbuffered output whenever you want to ensure that the output has been written before continuing. One example is

file.tell() inconsistency

我的未来我决定 提交于 2019-11-26 03:57:39
问题 Does anybody happen to know why when you iterate over a file this way: Input: f = open(\'test.txt\', \'r\') for line in f: print \"f.tell(): \",f.tell() Output: f.tell(): 8192 f.tell(): 8192 f.tell(): 8192 f.tell(): 8192 I consistently get the wrong file index from tell(), however, if I use readline I get the appropriate index for tell(): Input: f = open(\'test.txt\', \'r\') while True: line = f.readline() if (line == \'\'): break print \"f.tell(): \",f.tell() Output: f.tell(): 103 f.tell():

Setting smaller buffer size for sys.stdin?

时光怂恿深爱的人放手 提交于 2019-11-26 01:36:20
问题 I\'m running memcached with the following bash command pattern: memcached -vv 2>&1 | tee memkeywatch2010098.log 2>&1 | ~/bin/memtracer.py | tee memkeywatchCounts20100908.log to try and track down unmatched gets to sets for keys platform wide. The memtracer script is below and works as desired, with one minor issue. Watching the intermediate log file size, memtracer.py doesn\'t start getting input until memkeywatchYMD.log is about 15-18K in size. Is there a better way to read in stdin or

How to make output of any shell command unbuffered?

醉酒当歌 提交于 2019-11-26 00:59:54
问题 Is there a way to run shell commands without output buffering? For example, hexdump file | ./my_script will only pass input from hexdump to my_script in buffered chunks, not line by line. Actually I want to know a general solution how to make any command unbuffered? 回答1: AFAIK, you can't do it without ugly hacks. Writing to a pipe (or reading from it) automatically turns on full buffering and there is nothing you can do about it :-(. "Line buffering" (which is what you want) is only used when

An algorithm for inflating/deflating (offsetting, buffering) polygons

末鹿安然 提交于 2019-11-26 00:17:32
问题 How would I \"inflate\" a polygon? That is, I want to do something similar to this: The requirement is that the new (inflated) polygon\'s edges/points are all at the same constant distance from the old (original) polygon\'s (on the example picture they are not, since then it would have to use arcs for inflated vertices, but let\'s forget about that for now ;) ). The mathematical term for what I\'m looking for is actually inward/outward polygon offseting . +1 to balint for pointing this out.