pub struct BufferPool<T: Buffer> { /* private fields */ }Expand description
A pool of reusable memory buffers to optimize memory allocation for Sv2 message frames.
Manages memory slices across three pool modes: back (default), front, and system memory. It reuses preallocated memory slices, minimizing the need for frequent memory allocation. The pool is thread-safe, using atomic state tracking.
Type T implements the Buffer trait, which defines how memory is handled in the buffer
pool. BufferFromSystemMemory is used as the default system memory allocator.
Implementations§
Source§impl BufferPool<BufferFromSystemMemory>
impl BufferPool<BufferFromSystemMemory>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Creates a new BufferPool with the specified memory capacity, in bytes.
Initializes the buffer pool with pre-allocated memory (inner_memory) and sets the pool
mode to the back. The buffer pool uses BufferFromSystemMemory as a fallback when the
buffer sections are full.
Source§impl<T: Buffer> BufferPool<T>
impl<T: Buffer> BufferPool<T>
Sourcepub fn is_front_mode(&self) -> bool
pub fn is_front_mode(&self) -> bool
Checks if the buffer pool is operating in the front mode.
This mode indicates that the back of the buffer pool has been filled and the system is now
using the front section for memory allocation. Returns true if the pool is in front mode,
otherwise false.
Sourcepub fn is_back_mode(&self) -> bool
pub fn is_back_mode(&self) -> bool
Checks if the buffer pool is operating in the back mode.
The back mode is the default state, where the buffer pool first tries to allocate memory.
Returns true if the pool is in back mode, otherwise false.
Sourcepub fn is_alloc_mode(&self) -> bool
pub fn is_alloc_mode(&self) -> bool
Checks if the buffer pool is operating in the system memory allocation mode.
This mode is used when both the back and front sections of the buffer pool are full,
leading the system to allocate memory from the heap, which has performance trade-offs.
Returns true if the pool is in alloc mode, otherwise false.
Trait Implementations§
Source§impl<T: Buffer> Buffer for BufferPool<T>
impl<T: Buffer> Buffer for BufferPool<T>
Source§fn reserve(&mut self, len: usize) -> &mut [u8] ⓘ
fn reserve(&mut self, len: usize) -> &mut [u8] ⓘ
len more bytes after the data written so far and returns that space,
without counting any of it as written. Read moreSource§fn commit(&mut self, len: usize)
fn commit(&mut self, len: usize)
len bytes of the last reservation as written, and ends that
reservation. Read moreSource§fn get_data_owned(&mut self) -> Self::Slice
fn get_data_owned(&mut self) -> Self::Slice
shared_state that the slice occupies. The pool
now points to the next set of uninitialized space.Source§fn frame(&self) -> &[u8] ⓘ
fn frame(&self) -> &[u8] ⓘ
Source§fn frame_mut(&mut self) -> &mut [u8] ⓘ
fn frame_mut(&mut self) -> &mut [u8] ⓘ
Source§fn len(&self) -> usize
fn len(&self) -> usize
Source§fn truncate(&mut self, len: usize)
fn truncate(&mut self, len: usize)
len, like Vec::truncate: a
len at or past the committed length changes nothing, so the frame can only shrink.