hedzr / go-ringbuf

Lock-free MPMC Ring Buffer (Generic) for SMP, in golang. Some posts in chinese:
https://hedzr.com/algorithm/golang/ringbuf-index/
Apache License 2.0
78 stars 4 forks source link

当队列满时,再添加可以自动覆盖最旧的吗? #5

Closed bagualing closed 1 month ago

bagualing commented 1 month ago

跟着示例代码试了一下,当队列满时,再添加新元素,会直接返回队列已满的错误。 是否可以当队列满时,直接自动覆盖最旧的元素,而不是返回已满的错误呢?

hedzr commented 1 month ago

可以尝试做一份,今晚看看是否可行,太复杂的话就只好暂且挂起

hedzr commented 1 month ago

Added overlapped ring buffer impl, and deeper testing will be covered in recently days. The stable point was arrived, and the new version would be released.

An overlapped ring buffer will overwrite the existing head element in putting new elem but the ring buffer is full.

The original ring buffer of ourselves is to return a wrong state and stop putting action, see the ErrQueueFull.

The new overlapped ring buffer will be created by calling NewOverlappedRingBuffer().

Any issues are welcome.

bagualing commented 1 month ago

Nice job!