-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Since buffer->tail == buffer->head
means empty, and tail
points at the first free position, the last slot before tail
catching around to head
is not actually usable.
If the data
array is 64 bytes long, only 63 of these are actually usable at a time.
This reflects in the strange fact that ringBufferFreeSpace
and ringBufferMaxSize
using a mask as if it was a length. It checks out since the mask is the length minus one, but I think that this is hiding what the real culprit is: one slot is wasted.
Suggestions:
- use an actual -1 instead of mask to compute free space / max size
- document the fact that only len - 1 of
data
is usable at any given time - consider modifying the code to make
tail
point at the last written slot. There might be more thinking into that, especially how to check for emptiness.
Metadata
Metadata
Assignees
Labels
No labels