[][src]Struct growable::GrowablePool

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]);

Methods

impl GrowablePool
[src]

Creates a new pool with default options.

Notes

See GrowablePoolBuilder for advanced configuration.

Creates a new pool builder with default options.

Returns true if a reallocation will be needed to allocate an another one object.

Returns the current amount of allocations that this pool can provide without a reallocation.

Allocates a new Reusable from the pool.

Notes

If no Growable is available for allocation, the entire pool will be reallocated.

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 Default for GrowablePool
[src]

impl Clone for GrowablePool
[src]

Performs copy-assignment from source. Read more

impl Debug for GrowablePool
[src]

Auto Trait Implementations

impl Send for GrowablePool

impl Sync for GrowablePool

Blanket Implementations

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

impl<T> From for T
[src]

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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