Buffer (computer science)

From Wikipedia, the free encyclopedia

In computing, a buffer is a region of memory used to temporarily hold output or input data, comparable to buffers in telecommunication. The data can be output to or input from devices outside the computer or processes within a computer. Buffers can be implemented in either hardware or software, but the vast majority of buffers are implemented in software. Buffers are used when there is a difference between the rate at which data is received and the rate at which it can be processed, or in the case that these rates are variable, for example in a printer spooler.

Since computers operate in binary, at the lowest level, a single byte in memory could be considered a buffer for (usually) 8 bits, and even a Processor register can be considered a buffer for 16 or 32 bits. In practice however, a buffer is thought of as being a contiguous area of memory of a certain length, but normally greater than one.

Logical records are often grouped into fixed length blocks (the "physical record"), to improve the efficiency of hard drives. The memory allocated for these were often known as "file buffers" and provided a measure of asynchronous processing between cpu and hardware channel by using two or more in a "flip-flop" fashion.

As the first buffer fills with output records, the operating system initiates an I/O operation on the first buffer and immediately switches to an empty buffer to receive the next set of (logical) records before the first buffer has completed its physical write. A similar method applies to input processing and the combined effect of large physical record sizes and buffering improved overall performance dramatically by compensating for the faster CPU speed relative to I/O hardware devices.

[edit] Comparison of Buffers and Cache

Buffers are allocated by various processes to use as input queues, etc. Most of the time, buffers are some processes' output, and they are file buffers. A simplistic explanation of buffers is that they allow processes to temporarily store input in memory until the process can deal with it.

Cache is typically frequently requested disk I/O. If multiple processes are accessing the same files, much of those files will be cached to improve performance (RAM being much faster than hard drives).

[edit] See also