Concept

How do buffered and unbuffered file input/output differ?

ComputerScienceOne / Buffered and Unbuffered

"9.1.3. Buffered and Unbuffered When processing files the input/output may be either buffered or unbuffered. A buffered input or output “stream” is one in which data that is read/written is actually stored in memory in a “buffer” until such a time as the buffer is “flushed” and the accumulated data is passed to/from the actual file. For example, in a buffered output file, our program could write several kilobytes of data to the output file, but it might not actually be written to the file right away. Instead, those kilobytes of data are stored in memory until the buffer fills up or some other event takes place to cause the buffer to be flushed. At that point, the data stored in the buffer is emptied and written to the file. Buffered input/output is used because I/O operations are expensive in terms of system resources and can slow the system down. Because of this, it is better to keep I/O operations as infrequent as possible. Buffers help to reduce the number of I/O operations performed by a program by making them less frequent. There are some instances in which we want unbuffered I/O. When error messages are written to the standard error output for example, we would prefer to know about errors as soon as possible rather than waiting for error messages to accumulate in a buffer. Using an unbuffered output means that data is written to the standard error (which is a file) immediately. However, because errors are (hopefully) infrequent and (likely) fatal, this is not a performance issue."

Related Ideas

How do buffered and unbuffered file input/output differ? | ComputerScienceOne | Bifalgorithm | Bifalgorithm