pub struct BufferPool<T: Buffer> {
pub mode: PoolMode,
/* 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.
Fields§
§mode: PoolMode
Tracks the current mode of memory allocation (back, front, or system).
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
.
Source§impl<T: Buffer> BufferPool<T>
impl<T: Buffer> BufferPool<T>
Sourcepub fn droppable(&self) -> bool
pub fn droppable(&self) -> bool
Determines if the BufferPool
can be safely dropped.
Returns true
if all memory slices managed by the buffer pool have been released (i.e.,
the shared_state
is zero), indicating that all the slices are dropped. This check helps
prevent dropping the buffer pool while it’s still in use.
Trait Implementations§
Source§impl<T: Buffer> Buffer for BufferPool<T>
impl<T: Buffer> Buffer for BufferPool<T>
Source§fn get_writable(&mut self, len: usize) -> &mut [u8]
fn get_writable(&mut self, len: usize) -> &mut [u8]
Source§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 get_data_by_ref(&mut self, len: usize) -> &mut [u8]
fn get_data_by_ref(&mut self, len: usize) -> &mut [u8]
Source§fn get_data_by_ref_(&self, len: usize) -> &[u8]
fn get_data_by_ref_(&self, len: usize) -> &[u8]
Source§fn len(&self) -> usize
fn len(&self) -> usize
Source§fn danger_set_start(&mut self, index: usize)
fn danger_set_start(&mut self, index: usize)
index
. This can be useful for performance optimizations in situations where older data
is no longer needed, but its use can be unsafe unless you understand its implications.