pub struct Pool<T> { /* private fields */ }
Expand description
A lock-free memory pool
Implementations§
source§impl<T> Pool<T>
impl<T> Pool<T>
sourcepub fn alloc(&self) -> Option<Box<T, Uninit>>
pub fn alloc(&self) -> Option<Box<T, Uninit>>
Claims a memory block from the pool
Returns None
when the pool is observed as exhausted
NOTE: This method does not have bounded execution time because it contains a CAS loop
sourcepub fn free<S>(&self, value: Box<T, S>)where
S: 'static,
pub fn free<S>(&self, value: Box<T, S>)where
S: 'static,
Returns a memory block to the pool
NOTE: T
’s destructor (if any) will run on value
iff S = Init
NOTE: This method does not have bounded execution time because it contains a CAS loop
sourcepub fn grow(&self, memory: &'static mut [u8]) -> usize
pub fn grow(&self, memory: &'static mut [u8]) -> usize
Increases the capacity of the pool
This method might not fully utilize the given memory block due to alignment requirements.
This method returns the number of new blocks that can be allocated.
sourcepub fn grow_exact<A>(&self, memory: &'static mut MaybeUninit<A>) -> usize
pub fn grow_exact<A>(&self, memory: &'static mut MaybeUninit<A>) -> usize
Increases the capacity of the pool
Unlike Pool.grow
this method fully utilizes the given
memory block
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more