pub struct RingBuffer { /* private fields */ }Expand description
Chunked ring buffer.
A ring buffer which is logically split into chunks where each chunk is
at least chunk_size. A transaction API is provided if the caller needs
to make multiple writes that must not be split across chunks. Chunks are
discarded in their entirety when needed to make space.
A smaller chunk size has the advantage of higher utilization of the space in the ring buffer in exchange for more memory used keeping track of chunk boundaries and more work done when discarding chunks. Conversely a larger chunk size means that utilization of the buffer space has higher variance, but less memory is needed and discards are less often. Users should choose a chunk size appropriate for their use case.
Implementations§
Source§impl RingBuffer
impl RingBuffer
Sourcepub fn new(size: usize, chunk_size: usize) -> Self
pub fn new(size: usize, chunk_size: usize) -> Self
Create a new chunked ring buffer.
The capacity of the buffer is set to the next multiple of chunk_size
larger than or equal to size.
Sourcepub fn get_view(&self) -> (&[u8], &[u8])
pub fn get_view(&self) -> (&[u8], &[u8])
Return the data stored in the ring buffer as two byte slices.
Sourcepub fn start_transaction(&mut self) -> Transaction<'_> ⓘ
pub fn start_transaction(&mut self) -> Transaction<'_> ⓘ
Start a transaction that groups a series of writes.