ring buffer

A fixed-size array used as a loop: when writes reach the end they wrap to the start, overwriting the oldest data.

In more detail

A head index marks the oldest item and a tail index the next write position, and both advance with modulo arithmetic. Memory is allocated once and never grows, which suits streams of sensor readings, logs and audio. It always holds the most recent capacity-many values.

Example

An SSE server replays recent events from a ring buffer to reconnecting clients.

Related terms

Taught in

References