AllowOverflow

Dec 31, 2009 at 9:22 PM

I guess AllowOverflow is the property to choose whether one CircularBuffer can overwrite his old values. If it's the case, it doesn't work when you reach the buffer capacity. It will cause an IndexOutOfRangeException in the Put method because of this : 

buffer[tail] = item;
            if (tail++ == capacity)
                tail = 0
buffer[tail] = item;
if (tail++ == capacity)
    tail = 0;

When entering the Put method, if tail is equal to the buffer capacity - 1 then tail will be equal to the capacity when exiting. The next time we enter Put, tail will be equal to the buffer capacity and it will crash. Maybe the code should have been :

buffer[tail] = item;
if (++tail == capacity)
    tail = 0;

 

Dec 31, 2009 at 9:43 PM

Actually I think I missunderstand the way your CircularBuffer works. 

I'd like to do this :

 

            int capacity = 5;
            var buffer = new CircularBuffer<byte>(capacity, true);
            for (byte i = 0; i < capacity * 3; ++i)
                buffer.Put(i);

and have in the buffer { 10, 11, 12, 13, 14, 15 }

Is it possible ?

 

Nov 20, 2010 at 7:42 AM

This is exactly what I want as well and from my understanding this is how a circular buffer should behave.  Did you ever confirm if this works?

Nov 20, 2010 at 9:34 PM
It doesn't work with this library.

Coordinator
Jul 7, 2012 at 3:11 AM

Indeed, this problem was due to my haste in writing the code. It ought to be fixed now.