Distinguish Empty from Full in a Circular Buffer
Distinguish Empty from Full in a Circular Buffer
Try With both pointers at the Start slot and the count at 0, press Step to watch where the tail moves as records are written.
Same pointers, different counts
Circular buffer
Start slot
Clear
↓ Head
↓ Tail
Following slot
Clear
↓ Head
↓ Tail
Later slot
Clear
↓ Head
↓ Tail
Last slot
Clear
↓ Head
↓ Tail
Capacity C
Count: 0
Empty
Head · Next removal
Tail · Next write
Slots are schematic. The dashed arrow wraps from the end back to the start.
Empty buffer
The head and tail point to the same slot. A count of zero identifies an empty buffer.
Observe At count 0, Head and Tail share the Start slot. Tail moves away during the writes and returns to Head when the readout reaches Count C and shows Full.
Explain Each write advances Tail and raises the count by 1. Tail wraps to Head after the last free slot is filled, so count 0 means empty and count C means full even though the pointers coincide in both cases.
Technical boundaries. The slot layout is schematic, and the dashed arrow represents wraparound in array order. The replay follows a buffer that tracks occupancy with a count. It stops after removing the oldest item and leaves the handling of an attempted write to a full buffer unspecified.