AbstractFIFO


#1

Dear Jules,

I just wonder if in this fragment:

[code]void AbstractFifo::finishedWrite (int numWritten) noexcept
{
jassert (numWritten >= 0 && numWritten < bufferSize);
int newEnd = validEnd.value + numWritten;
if (newEnd >= bufferSize)
newEnd -= bufferSize;

validEnd = newEnd;

}
[/code]
would be:

instead of:

Because if I use a fixed input buffer size (let’s say size =2048), each time I need to fill it, I’d do it fully (2048 floats) but it raises me this assert.

On the other hand, this code has an asymmetry related to AbstractFifo::finishedRead:

[code]void AbstractFifo::finishedRead (int numRead) noexcept
{
jassert (numRead >= 0 && numRead <= bufferSize);

int newStart = validStart.value + numRead;
if (newStart >= bufferSize)
    newStart -= bufferSize;

validStart = newStart;

}
[/code]
where the assert has a <= comparator operator instead of a < op.

Gabriel

P.S. The more I am able to exploit your code the more I admire you!


#2

The “problem” is when you fill the buffer with the whole buffersize, than the end-Pointer has the same position as the begin pointer, which is an ambiguous state, this can mean that the buffer is full, or empty.

So, thats why you have add 1 to your buffersize. (This is something you learn when you write your own fifo-class ( http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=10118 )


[Solved] Can't fill up AbstractFifo - (totalSize - 1) is the max allowed?
#3

Chkn, I insist, I think the assertion must contain a <= comparison op. Let’s see what Jules assesment will say.
OTH, I’ve read the post and it was a very thick discussion. I just wonder if TheVinn is Ph. D. Sheldon Cooper disguised!
(All my affection to you TheVinn!)

Gabriel


#4

No - the assertion is correct. Like chkn says, you need at least one extra slot in your fifo to avoid the start/end pointers being the same.


#5

Ok, then!