tags:

views:

51

answers:

1

I heard the word buffer after a long time today and wondering if somebody can give a good overview of buffer and some examples of how it matters in today's world.

+1  A: 

A buffer is generally a portion of memory that contains data that has not yet been fully committed to its intended device. In the case of buffered I/O, generally there is a fast device and a slow device. The devices themselves need not have disparate speeds, but perhaps the interfaces between them differ or perhaps it is more time-consuming to either produce or consume the data than the other part is.

The idea is that you temporarily store the generated data in a buffer so that it is not lost when the slower device isn't ready to handle it. Once the device is ready, the another buffer may take the current buffer's place and the consuming device will process the data in the first buffer.

In this manner, the slower device receives the data at a moderated pace rather than the fire-hose that the original data source can be.

San Jacinto
Thanks for the answer. Can we consider writing to a file system a buffered write? and is considered faster?
CodeToGlory
And, the faster device can be turned off if the buffer is full. In embedded devices this may be critical as turning off reduces power usage. A situation with a hard-drive and a floppy-drive: if you move data from the HD to the FD, the HD needs to wait for the FD. If you buffer the HD, you can turn it off, so the noise is reduced and less power consumption (think: laptop) and longer device lifetime. The principle applies to all operations that have different timing; it's to reduce overhead.
Pindatjuh
@CodeToGlory Writes to a file system are usually buffered because the source of the data (CPU, memory) is usually quite fast compared to the devices and interfaces where the file system resides (hard disk, flash, etc.). Even if the hardware underneath the file system is just as fast, you have an "accounting" overhead that slows the process down so that the data source becomes too fast (or else you aren't really running a file system).
San Jacinto