pub struct Pool<P: PoolAllocator<T>, T> { /* private fields */ }
Expand description
A struct representing an object pool.
This struct uses an allocator to create and manage objects, and stores them in an ArrayQueue.
Implementations§
source§impl<P: PoolAllocator<T>, T> Pool<P, T>
impl<P: PoolAllocator<T>, T> Pool<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 Pool 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) -> Arc<Self>
pub fn to_rc(self) -> Arc<Self>
Wraps the pool allocator with an atomic 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) -> RefGuard<'_, P, T>
pub fn get(&self) -> RefGuard<'_, 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: Arc<Self>) -> RcGuard<P, T>
pub fn get_rc(self: Arc<Self>) -> RcGuard<P, T>
Gets an object from the pool that holds an arc 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.