Skip to main content

MemPool

Struct MemPool 

Source
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

Source

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: If true, 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.

Source

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: If true, access to the pool is protected by a mutex.
  • block_sizes: A slice of usize defining 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).

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for MemPool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for MemPool

Source§

fn drop(&mut self)

Deletes the memory pool when the MemPool object goes out of scope.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.