pub struct LocalPool<P: PoolAllocator<T>, T> { /* private fields */ }Expand description
A struct representing an object pool for local thread, it cannot be moved between threads.
This struct uses an allocator to create and manage objects, and stores them in an array.
Implementations§
Source§impl<P: PoolAllocator<T>, T> LocalPool<P, T>
impl<P: PoolAllocator<T>, T> LocalPool<P, T>
Sourcepub fn new_prefilled(pool_size: usize, allocator: P) -> Self
pub fn new_prefilled(pool_size: usize, allocator: P) -> Self
Creates a new LocalPool with a given size and allocator.
This method immediately fills the pool with new objects created by the allocator.
Sourcepub fn new(pool_size: usize, allocator: P) -> Self
pub fn new(pool_size: usize, allocator: P) -> Self
Creates a new Object Pool with a given size and allocator.
Unlike Self::new_prefilled, this method does not immediately fill
the pool with objects.
Sourcepub fn to_rc(self) -> Rc<Self>
pub fn to_rc(self) -> Rc<Self>
Wraps the pool allocator with an reference counter, enabling the
use of Self::get_rc to obtain pool-allocated objects that rely on
reference counted references instead of borrowed references.
Sourcepub fn get(&self) -> RefLocalGuard<'_, P, T>
pub fn get(&self) -> RefLocalGuard<'_, P, T>
Gets an object from the pool.
If the pool is empty, a new object is created using the allocator.
Sourcepub fn get_rc(self: Rc<Self>) -> RcLocalGuard<P, T>
pub fn get_rc(self: Rc<Self>) -> RcLocalGuard<P, T>
Gets an object from the pool that holds an rc reference to the owning
pool. Allocated objects are not as efficient as those allocated by
Self::get method but they are easier to move as they are not limited
by allocator lifetime directly.
If the pool is empty, a new object is created using the allocator.