pub struct MemoryPool<T> { /* private fields */ }Expand description
Memory pool for reducing allocation overhead.
A capacity-bounded, lock-free object pool: Self::deallocate stores up to
max_size objects for reuse and Self::allocate pops a stored object or
falls back to T::default(). The freelist mechanics live in
LockFreeStack; this type only adds the pool vocabulary
(allocate/deallocate) over the stack’s fixed slot capacity.
Implementations§
Source§impl<T> MemoryPool<T>
impl<T> MemoryPool<T>
Sourcepub fn new(max_size: usize) -> Self
pub fn new(max_size: usize) -> Self
Create a new memory pool retaining at most max_size objects.
Sourcepub fn allocate(&self) -> Twhere
T: Default,
pub fn allocate(&self) -> Twhere
T: Default,
Allocate an object from the pool or create new if pool is empty
Sourcepub fn deallocate(&self, item: T)
pub fn deallocate(&self, item: T)
Return an object to the pool for reuse.
When the pool already holds max_size objects the item is dropped;
this is the pool’s documented retention cap, not an error condition.
Auto Trait Implementations§
impl<T> !Freeze for MemoryPool<T>
impl<T> !RefUnwindSafe for MemoryPool<T>
impl<T> Send for MemoryPool<T>where
LockFreeStack<T>: Send,
impl<T> Sync for MemoryPool<T>where
LockFreeStack<T>: Sync,
impl<T> Unpin for MemoryPool<T>where
LockFreeStack<T>: Unpin,
impl<T> UnsafeUnpin for MemoryPool<T>where
LockFreeStack<T>: UnsafeUnpin,
impl<T> UnwindSafe for MemoryPool<T>where
LockFreeStack<T>: UnwindSafe,
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