pub struct MemoryPool<T, const SIZE: usize> {
chunks: [MemoryPoolInner<T>; SIZE],
}Expand description
Interrupt- and thread-safe memory pool.
See module-level documentation for more information.
Fields§
§chunks: [MemoryPoolInner<T>; SIZE]Implementations§
Source§impl<T, const SIZE: usize> MemoryPool<T, SIZE>
impl<T, const SIZE: usize> MemoryPool<T, SIZE>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new MemoryPool.
SIZE is required to be larger than 0.
Sourcepub fn reserve(&self) -> Option<MemoryPoolToken<'_, T>>
pub fn reserve(&self) -> Option<MemoryPoolToken<'_, T>>
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>
pub fn chunk(&self, init_value: T) -> Result<Chunk<'_, T>, T>
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
pub fn chunks_available(&self) -> usize
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.