Skip to main content
Definition Website Computer and Technology

Ring Buffer

Subject: Computer and Technology noun /ˈrɪŋ ˌbʌf.ər/ 1 definition

  1. Definition (noun)

    Entry #49 · Updated

    A Ring Buffer (also known as a circular buffer or cyclic buffer) is a fixed-capacity, first-in, first-out (FIFO) data structure that uses a single contiguous array as though its end were connected back to its start. Separate read (head) and write (tail) indices advance through the array as items are removed and appended, wrapping back to zero via modulo arithmetic or bitwise masking without shifting remaining elements in memory. Because all storage is preallocated upfront, insertions and removals execute in constant O(1) time with predictable memory overhead and strong CPU cache locality, making the structure essential for streaming I/O, real-time audio pipelines, and producer-consumer queues—bounded by the fixed capacity that requires implementations to either overwrite the oldest entries or block new writes when full.

    Common Types

    • Overwriting Ring Buffer: Advances past and overwrites the oldest unread items once full, making it well suited for rolling telemetry logs, flight-recorder traces, and media jitter buffers where fresh data takes priority.

    • Blocking Ring Buffer: Rejects or suspends writes when full and pauses reads when empty, guaranteeing lossless delivery in bounded producer-consumer queues and operating system I/O buffers.

    • Lock-Free Ring Buffer: Coordinates concurrent threads—most commonly in single-producer, single-consumer (SPSC) designs—using atomic index updates and memory barriers rather than mutexes, minimizing latency in high-throughput messaging and real-time processing.

    • Mirrored Virtual-Memory Ring Buffer: Maps the same underlying physical memory pages twice into adjacent virtual address ranges so wrapped reads and writes appear contiguous, eliminating split-copy boundary checks.

    Example

    An embedded audio synthesizer exchanges 48 kHz PCM samples through a 4,096-slot ring buffer between a DMA hardware interrupt handler and a digital signal processing thread. As the interrupt writes incoming frames and wraps its tail index from slot 4,095 back to 0 via a bitwise mask (& 4095), the processing thread continuously consumes frames from the head index without allocating heap memory or shifting array elements.