4 ms·
for some reason, i always had problems with the concept of ring buffers - because what happens if end wraps around and overtakes start? it always takes me a fe
by stefs 2y ago
for some reason, i always had problems with the concept of ring buffers - because what happens if end wraps around and overtakes start?
it always takes me a few seconds (well, more than a few actually) to work out that in that case, the buffer is just full (like every other buffer).
- bob1029 2y agoIn all the implementations I use, a full buffer simply blocks the producers. Nothing bad actually happens.
- stefs 2y agowell, that's the great thing - you even have options: block the producers or overwrite old values. just don't forget to increment the start pointer too when overwriting old values.
- flohofwoe 2y ago...and if you don't care about the oldest items being discarded, you can just continue writing and 'push the tail forward', e.g. a ringbuffer is perfect when you need to record a continuous stream of values, but only ever need to access the last N values.