General implementation of a ring buffer
There are two cases while reading/writing from/to a ring buffer:
First one is as you guess, is to write/read directly as if our ring buffer is an ordinary buffer. This case is suitable if income data doesn't causes overflow. If ring buffer overflows after incoming data you must have another case to handle it. This is the second case and it is very comprehensible as well as the first case. If your data overflows then push it from the beginning of the data structure. And in both cases you should adjust your begin/end indexes (or you can use pointers). These indexes holds the address/index of the last data on the buffer.
I implemented my own ring buffer data structure using C++ language like this:
Hiç yorum yok:
Yorum Gönder