Devices operate at different speeds (CPU is fast, disk is slow, keyboard is very slow). Data transfer between them needs temporary storage to bridge the speed gap.
Buffering is the use of temporary storage (in memory) to hold data while it’s being transferred between devices or between a device and an application.
- Data from slow device stored in buffer (memory)
- Fast device/CPU can read from buffer at its own speed
- Buffer decouples producer and consumer of data
- Can be single buffer, double buffer, or circular buffer
- Decouples speed differences between devices
- Can be single, double, or circular buffer
- Block devices use buffer cache (disk blocks)
- Character devices use line buffers or raw mode
- Built from: O System, O Software
- Builds into: O Request to Hardware Operation
- Related: Device Driver, DMA
- Contrasts with: No Buffering (unbuffered I/O is slow)
- Buffer overflow if consumer too slow
- Buffer too small = frequent I/O operations
- Buffer too large = wasted memory