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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for GrowablePool
[src]

Formats the value using the given formatter. Read more

impl Default for GrowablePool
[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl Send for GrowablePool

impl Sync for GrowablePool

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

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

Performs the conversion.

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

Creates owned data from borrowed data, usually by cloning. Read more

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

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

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

Performs the conversion.

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

Immutably borrows from an owned value. Read more

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

Mutably borrows from an owned value. Read more

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.

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

Performs the conversion.

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

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more