When you have ring buffer, you typically have 2 pointers or offsets, which signify start
and end
of the data in the buffer. Typical convention to tell if buffer is empty when start
== end
.
This convention leads to BUFFER_SIZE - 1
limitation on total numbers of items in ring buffer. If we were to allow to fill it to BUFFER_SIZE
, this would mean that start
== end
, and thus would be impossible to tell if buffer is completely empty or completely full.
If you create one more variable that keeps number of items in the buffer, this would be possible to tell apart and allow to fill buffer to the max. But it is easier to not do that and simply reduce max number of items by 1.