Buffer Definition

A buffer, also called buffer memory, is a portion of a computer's memory that is set aside as a temporary holding place for data that is being sent to or received from an external device, such as a hard disk drive (HDD), keyboard or printer.

The original meaning of buffer is a cushion-like device that reduces the shock from the contact of two objects. A buffer in a computer system is usually located between two devices that have different speeds for handling data or used when there is a difference in the timing of events. It is analogous to a reservoir, which captures water upstream and then lets it out at controlled speeds intended to prevent the lower river from overflowing its banks. Likewise, a buffer in a computer ensures that data has somewhere to go, i.e., into the buffer temporarily until its ultimate destination becomes available.

Buffers have a number of applications in computers. For example, CPUs (central processing units) have far higher speeds than HDDs, and thus data that is to be used by a CPU is first copied from a HDD to a buffer while the CPU is performing other tasks so that it will be available for the CPU to use at high speed, i.e., without wasting the CPU's time waiting for the data.

Most text editors store the file being written or edited in a buffer. The text is transferred to the HDD when it is saved, i.e., data from the buffer is copied over the original file on the HDD, thereby replacing it. Because changes are initially stored in a buffer, all of them will be lost if the computer crashes during an editing session. Thus, it is a good idea to frequently save files that are being worked on.

Pipes, which allow the output of one program to be used directly as an input to another program, often buffer the output, collecting it in chunks and sending it to the next program at intervals.

When a command is issued to print a document, the operating system copies the document to a printer buffer from which the printer can use it at its own pace. This frees the computer to perform other tasks while the printer is running in the background. Print buffering is called spooling.

Likewise, video cards contain a buffer so that images can be assembled and displayed while the computer is doing something else.

A ring buffer is a buffer of fixed size into which new data is placed back at its start when it is full, thereby overwriting the data that was first placed in it. Ring buffers are commonly used by device drivers (i.e., programs to control hardware devices such as disk drives, keyboards and printers). Also, the output messages from the kernel (i.e., core of the operating system) are stored in a ring buffer, the contents of which can be read using the dmesg command.

A buffer overflow is a common type of security attack on computers. It occurs when a program or process (i.e., an instance of a program in execution) attempts to store more data in a buffer than the buffer can hold. The extra information, which has to go somewhere, can overflow into adjacent buffers, thereby corrupting or overwriting the valid data held in them. In a buffer overflow attack, the extra data contains code designed to trigger specific actions that could change data, damage files or disclose confidential information.

Created July 7, 2005.
Copyright © 2005 The Linux Information Project. All Rights Reserved.