Buffering
A buffer is an area of memory set aside for temporarily storing data when it is being transferred from one place to another. Buffers are widely used for input and output of data.

When data is input from a file (eg from a magnetic disc) it is transferred one block at a time. Several records may be stored in one block - or one record may need a number of blocks. The block is transferred and stored in a buffer in memory, from where it is processed.

In the same way, when data is to be output to a file, it is stored in a buffer, and is only transferred to the file when the buffer is full.

This process will keep the number of transfers to a minimum and save time - but it needs some memory space for the buffer.

Buffers are also used to overcome the problem of different speeds of peripherals and processors - processors operate thousands of times faster than printers. When data is sent to a printer, it is handled independently of the processor which is left free to carry on with other processing. The data to be printed is stored in a print buffer. This buffer may be in memory or actually in the printer. The hardware takes over and prints the data. When the buffer needs re-filling, an interrupt is sent to the processor.

To speed up processing sometimes two buffers are used (double buffering) - so for example, one buffer can be filled while the other is processed.