fefa4ka / linked_ring

It's just in place replacement for ring buffer, but without taking up all that extra space for multiply buffers used by different producers-consumers.
15 stars 2 forks source link

Overflow Behavior for Linked Ring Buffer #1

Open fefa4ka opened 1 year ago

fefa4ka commented 1 year ago

It would be useful to add the option to allow the linked ring buffer to overflow when it is filled, discarding the oldest data in favor of the new data. This could be useful in certain scenarios where it is necessary to store more data in the buffer than it can hold.

Discussion

There are a few considerations to keep in mind when implementing this feature:

One approach could be to modify the lr_put() function to check if the buffer is full before adding a new element, and provide a flag or configuration option to allow users to specify whether they want to enable overflow behavior or not. This could be a general setting for the buffer that applies to all owners.

To let the user know that the buffer is being overwritten, the lr_put() function could return a special return code or status message indicating that the element was added to the buffer, but buffer is full and overflow behavior is enabled.

Alternatively, the buffer could be overwritten only for the specified owner, using the same mechanism.