Dealing with the "overflow" of data in a ring buffer
That's why a ring buffer has two pointers; a write pointer and a read pointer. When writing, you advance the write pointer. When reading, you advance the read pointer. If the write pointer overtakes the read pointer, then you drop some data and signal an overrun (or you stop the process that's producing the data, if possible). If the read pointer overtakes the write pointer, then you tell the reading process that there isn't any more data available to be read.