I have been trying to wrap my head around the modes of operations for the circular buffer data structure. It seems trivial that it works for a consumer-producer architecture where a consumer reads data a producer wrote earlier.
In this case, it shall be guaranteed that the data received by the consumer at the end of the program is exactly the same. i.e it doesn't matter if producer is writing much quicker/slower than the consumer is reading. one or the other have to wait and synchronize
What I don't understand is why the other mode where we override stale data is useful at all? In such cases, some of the data produced might not be read.
Can someone point out to some real-case scenarios?
PS: The example provided in Wikipedia is causing more confusion to me since it claims that you can have a consumer-producer with overriding mode as well.
The problem you can run into with a circular buffer is that, in cases where the producer produces data much faster than the consumer can read, you'll eventually run out of memory. For example if the producer is putting data into the buffer at 10 frames per second but the consumer can only read at 9 frames per second, eventually the buffer is going to fill up. Or if the consumer can normally keep up, but for some reason slows down long enough for the buffer to overflow.
As the Wikipedia article says:
So if the consumer can't keep up, the producer starts overwriting old data. There really aren't a lot of good options in this case. The producer could perhaps wait until the consumer catches up, but that's not possible in the case of real-time data (think of real-time telemetry from a spacecraft, for example).
Sometimes it's just not possible for the producer to pause. If the consumer can't keep up, data will be lost.