|
|
|
|
|
by falcolas
3477 days ago
|
|
> Doesn't it break the order invariant of the buffer, though No, if you increment the read pointer prior to the write pointer, the read pointer will still point at the oldest valid value in the buffer. So, in pseudo code: if (w+1 >= r) {
r = w + 2
}
w++
b[w-1] = value
For a debugging ring buffer (i.e. looking at it in a core file), you have the last value of the write pointer, so you can simply read from write pointer + 1 back around to the write pointer and have your messages in order. This makes the assumption that there is no readers of the debug buffer, so you're only having to deal with the one pointer. |
|