glycerine/rbuf

Write even if there is no capacity.

codeskyblue opened this issue · 4 comments

In my usage, I need have to write to the ring buffer, when there is no space, just auto advance some space.

Can I make a pr for the function WriteWithAdvance

Are you sure you understand the typical way/purpose of a ring buffer? When it is full it should block writers until the reader(s) can catch up. Thus it provides flow control.

I can see using a ring buffer as a kind of temporal LRU cache... in which case it would make sense to WriteAndMaybeOverwriteOldestData().

If that's what you have in mind, I would accept a PR with that (deliberately long and obnoxious name--to warn unsuspecting users).

I know what is ring buffer, it also looks great to store log with it. Just drop the oldest log is necessary to let the newest log can write into it.

In passing, for your log, hopefully you realize that if the log lines vary in length, you might obliterate the start of the oldest line still in the buffer, leaving the buffer to start at a partial line.

The PR, once you've made the 3 changes I noted in the comments, is okay.

I went ahead and applied my edits and committed.