3 ms·
This implementation should be avoided; it is weird, buggy, and unnecessarily complicated. In particular, using some pseudocode to simplify: rb = new RingBuf
by o11c 2y ago
This implementation should be avoided; it is weird, buggy, and unnecessarily complicated.
In particular, using some pseudocode to simplify:
rb = new RingBuffer(... capacity=3, orderedReads=false/*the default*/)
rb.put_all(A, B, C, D)
rb.get() // D
rb.put(E)
rb.get_all(3) // E, C, D again
I haven't looked for bugs with orderedReads=true (besides the obvious memory leak), but given the footguns and unnecessarily complications this should be avoided regardless.