3 ms·
Why is push() checking for overlap? I thought not caring about that was the point of a ring buffer? [EDIT:] To clarify for those who didn't (couldn't?) read TF
by jessaustin 10y ago
Why is push() checking for overlap? I thought not caring about that was the point of a ring buffer?
[EDIT:] To clarify for those who didn't (couldn't?) read TFA's first sentence, it specifically invokes "I've been writing ring buffers wrong all these years" [0], recently featured on HN.
[0] https://www.snellman.net/blog/archive/2016-12-13-ring-buffers/ https://www.snellman.net/blog/archive/2016-12-13-ring-buffer...
- LgWoodenBadger 10y agoI can't read the site because it's blocked for me, but isn't a ring-buffer a different class of data-structure than a queue? AIUI, queues are for non-lossy FIFO behavior.
- NotThe1Pct 10y agoMy $10/mo shared host is already spinning with ycomb+linkedin traffic. I shall upgrade...
- loeg 10y agoNo, ring buffers are just an implementation of a queue. You can implement lossy/lossless ring buffers or linked-list queues.
- deleted 10y ago[deleted]
- alfalfasprout 10y agoDepends how you use it. For buffering realtime data if latency is of chief concern then by all means, discard the old stuff. If the desired behavior is to block when the queue is full, then you need to check for an overlap.
- loeg 10y agoIf you're overwriting old data you still need to check for overlap and advance the read index if you're overrunning old data.
- jessaustin 10y agoThanks, this is what I was missing, and seems right in general. I think the old ring buffers I'm remembering just decided that reading out-of-order was a fitting punishment for not reading often enough. After all there is a bit of a race for the read index here...