pub struct MemPool { /* private fields */ }Expand description
A handle to a cFE Executive Services memory pool.
This struct is an RAII wrapper that ensures the underlying pool is deleted
when it goes out of scope. The memory for the pool itself must have a
'static lifetime.
Implementations§
Source§impl MemPool
impl MemPool
Sourcepub fn new(memory: &'static mut [u8], use_mutex: bool) -> Result<Self>
pub fn new(memory: &'static mut [u8], use_mutex: bool) -> Result<Self>
Creates a new memory pool from a statically allocated memory region.
This uses the default cFE block sizes for the pool.
The pool size must be an integral number of 32-bit words, the start address must be 32-bit aligned, and 168 bytes are reserved for internal bookkeeping.
§Arguments
memory: A mutable static byte slice to be used as the pool’s memory.use_mutex: Iftrue, access to the pool will be protected by a mutex.
§Errors
Returns an error if the memory pool cannot be created, e.g., due to an invalid memory pointer or size.
Sourcepub fn new_ex(
memory: &'static mut [u8],
use_mutex: bool,
block_sizes: &[usize],
) -> Result<Self>
pub fn new_ex( memory: &'static mut [u8], use_mutex: bool, block_sizes: &[usize], ) -> Result<Self>
Creates a new memory pool with user-defined block sizes.
§Arguments
memory: A mutable static byte slice for the pool’s memory.use_mutex: Iftrue, access to the pool is protected by a mutex.block_sizes: A slice ofusizedefining the bucket sizes for the pool.
§Errors
Returns an error if the pool cannot be created, e.g., due to an invalid argument, too many block sizes, or an external resource failure (like failing to create a mutex).
Sourcepub fn get_buf(&self, size: usize) -> Result<PoolBuffer<'_>>
pub fn get_buf(&self, size: usize) -> Result<PoolBuffer<'_>>
Allocates a buffer of at least size bytes from the pool.
The actual allocation is at least 12 bytes larger than requested (internal block header overhead). The returned buffer size is rounded up to the next available block size in the pool.
Returns a PoolBuffer guard. When this guard is dropped,
the memory is automatically returned to the pool.
§Errors
Returns an error if a buffer cannot be allocated, for example, if the pool is out of memory or the requested size is larger than the largest available block size.
Sourcepub fn stats(&self) -> Result<MemPoolStats>
pub fn stats(&self) -> Result<MemPoolStats>
Retrieves statistics about this memory pool.
§Errors
Returns an error if the pool handle is invalid or the underlying CFE call fails.
Sourcepub fn get_buf_info(&self, buf: &PoolBuffer<'_>) -> Result<usize>
pub fn get_buf_info(&self, buf: &PoolBuffer<'_>) -> Result<usize>
Gets information about a buffer previously allocated from this pool.
Returns the allocated size of the buffer.
§Errors
Returns an error if the pool handle is invalid or the provided buffer pointer does not belong to this pool.