agerasev/ringbuf

When the buffer is full, can you wrap around and overwrite?

psteffensen opened this issue · 5 comments

Hi,

I would like to overwrite when the buffer is full. Can that be done without using the consumer to remove values?

/Peter

Hi,

For now there is no way to remove values from ring buffer with producer.

The main idea of non-blocking ring buffer is that only producer can modify head pointer and only consumer can modify tail pointer. But to overwrite an item in ring buffer you need to both modify head and tail that may lead to data race, so in such case ring buffer must be locked which makes it blocking.

Anyway, now I see that this feature request is quite popular (e.g. #5, #13) so I think it's worth to consider the possibility of making a blocking version of ring buffer containing overwriting version of push* methods.

I've added the possibility to use the ring buffer in blocking way (just guard it with mutex) and push*_overwrite family of methods (example).

I've added the possibility to use the ring buffer in blocking way (just guard it with mutex) and push*_overwrite family of methods (example).

This is really great. Thanks a lot! I will try it out tonight.

@psteffensen is push_overwrite not implemented for LocalRb?

@psteffensen is push_overwrite not implemented for LocalRb?

Hmm, overwrite* methods are implemented for all ring buffers.
Maybe you forget to import the Rb trait?

I've added a test for LocalRb, it works well.