io-buffering

Understanding Ruby and OS I/O buffering

假如想象 提交于 2019-11-27 11:47:58
How does IO buffering work in Ruby? How often is data flushed to the underlying stream when using the IO and File classes? How does this compare to OS buffering? What needs to be done to guarantee that given data has been written to disk, before confidently reading it back for processing? Casper The Ruby IO documentation is not 100% clear on how this buffering works, but this is what you can extract from the documentation: Ruby IO has its own internal buffer In addition to that the underlying operating system may or may not further buffer data. The relevant methods to look at: IO.flush :

How do I flush a file in Perl?

最后都变了- 提交于 2019-11-27 09:12:01
I have Perl script which appends a new line to the existing file every 3 seconds. Also, there is a C++ application which reads from that file. The problem is that the application begins to read the file after the script is done and file handle is closed. To avoid this I want to flush after each line append, but I'm new to Perl and don't know how to do that. paxdiablo Try: use IO::Handle; $fh->autoflush; This was actually posted as a way of auto-flushing in an early question of mine , which asked about the universally accepted bad way of achieving this :-) TL/DR: use IO::Handle and the flush

Can I stop std::cout flushing on “\n”?

纵然是瞬间 提交于 2019-11-27 04:43:45
问题 According to to this post std::cout will automatically flush on \n when it is attached to an interactive device (e.g. a terminal window). Otherwise (e.g. when being piped to a file) it will act fully buffered and will only flush on .flush() or std::endl . Is there a way to override this behaviour in Microsoft Visual C++ so that I can select whether I want fully buffered or line buffered mode? 回答1: Contrary to anon's (Apr 28 '09) answer, this behavior has nothing to do with the operating

Lisp format and force-output

纵然是瞬间 提交于 2019-11-26 23:20:44
问题 I don't understand why this code behaves differently in different implementations: (format t "asdf") (setq var (read)) In CLISP it behaves as would be expected, with the prompt printed followed by the read, but in SBCL it reads, then outputs. I read a bit on the internet and changed it: (format t "asdf") (force-output t) (setq var (read)) This, again, works fine in CLISP, but in SBCL it still reads, then outputs. I even tried separating it into another function: (defun output (string) (format

Understanding Ruby and OS I/O buffering

大兔子大兔子 提交于 2019-11-26 15:46:11
问题 How does IO buffering work in Ruby? How often is data flushed to the underlying stream when using the IO and File classes? How does this compare to OS buffering? What needs to be done to guarantee that given data has been written to disk, before confidently reading it back for processing? 回答1: The Ruby IO documentation is not 100% clear on how this buffering works, but this is what you can extract from the documentation: Ruby IO has its own internal buffer In addition to that the underlying

How do I flush the cin buffer?

眉间皱痕 提交于 2019-11-25 22:57:53
问题 How do I clear the cin buffer in C++? 回答1: Possibly: std::cin.ignore(INT_MAX); This would read in and ignore everything until EOF . (you can also supply a second argument which is the character to read until (ex: '\n' to ignore a single line). Also: You probably want to do a: std::cin.clear(); before this too to reset the stream state. 回答2: I would prefer the C++ size constraints over the C versions: // Ignore to the end of file cin.ignore(std::numeric_limits<std::streamsize>::max()) //