AbstractFifo size vs. free space

I’m starting to use the juce::AbstractFifo, but got hang up on the following: When using the FIFO, the available space seems to be always the size minus 1:

juce::AbstractFifo fifo(512);
DBG("Free space: " << fifo.getFreeSpace());
DBG("Samples ready: " << fifo.getNumReady());

output:

Free space: 511
Samples ready: 0

Perhaps I’m missing some point here?

The valid region is stored as a start and an end. My guess is that when validStart == validEnd, this could indicate that the buffer is either completely empty, or completely full. To avoid this uncertainty, the buffer is not allowed to fill to the point where validStart and validEnd are equal. This means that the start and end being equal always indicates that the buffer is empty.

3 Likes

Ok, makes sense. I’d love to see it mentioned in the docs though (if I didn’t miss it).