pub struct MemoryPool<T, const SIZE: usize> { /* private fields */ }Expand description
Interrupt- and thread-safe memory pool.
See module-level documentation for more information.
Implementations§
Source§impl<T, const SIZE: usize> MemoryPool<T, SIZE>
impl<T, const SIZE: usize> MemoryPool<T, SIZE>
Sourcepub const fn new() -> MemoryPool<T, SIZE>
Available on crate feature data-support-can only.
pub const fn new() -> MemoryPool<T, SIZE>
data-support-can only.Creates a new MemoryPool.
SIZE is required to be larger than 0.
Sourcepub fn reserve(&self) -> Option<MemoryPoolToken<'_, T>>
Available on crate feature data-support-can only.
pub fn reserve(&self) -> Option<MemoryPoolToken<'_, T>>
data-support-can only.Reserves an element in the MemoryPool.
Returns None if no element is available.
The returned token has to be initialized via MemoryPoolToken::init before use.
See MemoryPool::chunk for a convenience wrapper combining reserving and initializing a Chunk.
Sourcepub fn chunk(&self, init_value: T) -> Result<Chunk<'_, T>, T>
Available on crate feature data-support-can only.
pub fn chunk(&self, init_value: T) -> Result<Chunk<'_, T>, T>
data-support-can only.Retrieves a Chunk from the MemoryPool and initializes it with init_value.
Returns Err(init_value) if no more Chunks are available.
Convenience wrapper combining MemoryPool::reserve and `MemoryPoolToken::init.
Sourcepub fn chunks_available(&self) -> usize
Available on crate feature data-support-can only.
pub fn chunks_available(&self) -> usize
data-support-can only.Calculates the amount of chunks currently available.
Due to accesses from interrupts and/or other threads, this value might not be correct. Only intended for metrics.