Struct growable::GrowablePool [−][src]
A pool of Growable
objects. Unlike a typical Arena-based allocator it probably
will not be able to decrease a memory fragmentation or provide some strong
guarantees about frequency of allocations in your code but instead
can be used to reduce the total amount of allocations in an amortized way
by reusing the same memory to store different objects.
Examples
Let’s start off by creating a default GrowablePool
.
// A default pool will not allocate anything just yet though. let mut pool = GrowablePool::default();
We can now use it to allocate some data and do something with it.
// Actually allocates a block capable to store at least this 6 bytes. let arr: Reusable<[u8]> = pool.allocate([1, 2, 3, 4, 5, 6]); assert_eq!(&*arr, &[1, 2, 3, 4, 5, 6]);
An then return it back to the pool..
pool.free(arr);
.. and reuse the same heap to store something else.
// No allocation is required. let arr: Reusable<[u8]> = pool.allocate([1, 2, 3]); assert_eq!(&*arr, &[1, 2, 3]);
Implementations
impl GrowablePool
[src]
pub fn new() -> Self
[src]
pub fn builder() -> GrowablePoolBuilder
[src]
Creates a new pool builder with default options.
pub fn is_empty(&self) -> bool
[src]
Returns true if a reallocation will be needed to allocate an another one object.
pub fn len(&self) -> usize
[src]
Returns the current amount of allocations that this pool can provide without a reallocation.
pub fn allocate<T>(&mut self, t: T) -> Reusable<T>
[src]
Allocates a new Reusable
from the pool.
Notes
If no Growable
is available for allocation, the entire pool will be reallocated.
pub fn free<T>(&mut self, t: Reusable<T>) where
T: ?Sized,
[src]
T: ?Sized,
Trait Implementations
impl Clone for GrowablePool
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for GrowablePool
[src]
impl Default for GrowablePool
[src]
Auto Trait Implementations
impl RefUnwindSafe for GrowablePool
impl Send for GrowablePool
impl Sync for GrowablePool
impl Unpin for GrowablePool
impl UnwindSafe for GrowablePool
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,