Struct growable::GrowablePool[][src]

pub struct GrowablePool { /* fields omitted */ }

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]

Creates a new pool with default options.

Notes

See GrowablePoolBuilder for advanced configuration.

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]

Returns the Reusable back to the pool, marking it available for a next allocation.

Notes

With overgrow disabled the Growable might be dropped entirely if there is not enough free space available in the pool.

Trait Implementations

impl Clone for GrowablePool[src]

impl Debug for GrowablePool[src]

impl Default for GrowablePool[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.