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]
impl GrowablePoolpub fn new() -> Self[src]
pub fn new() -> Selfpub fn builder() -> GrowablePoolBuilder[src]
pub fn builder() -> GrowablePoolBuilderCreates a new pool builder with default options.
pub fn is_empty(&self) -> bool[src]
pub fn is_empty(&self) -> boolReturns true if a reallocation will be needed to allocate an another one object.
pub fn len(&self) -> usize[src]
pub fn len(&self) -> usizeReturns the current amount of allocations that this pool can provide without a reallocation.
pub fn allocate<T>(&mut self, t: T) -> Reusable<T>[src]
pub fn allocate<T>(&mut self, t: T) -> Reusable<T>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]
pub fn free<T>(&mut self, t: Reusable<T>) where
T: ?Sized, Trait Implementations
impl Clone for GrowablePool[src]
impl Clone for GrowablePoolfn clone(&self) -> Self[src]
fn clone(&self) -> SelfReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl Debug for GrowablePool[src]
impl Debug for GrowablePoolfn fmt(&self, formatter: &mut Formatter) -> Result[src]
fn fmt(&self, formatter: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl Default for GrowablePool[src]
impl Default for GrowablePoolAuto Trait Implementations
impl Send for GrowablePool
impl Send for GrowablePoolimpl Sync for GrowablePool
impl Sync for GrowablePoolBlanket Implementations
impl<T> From for T[src]
impl<T> From for Timpl<T, U> Into for T where
U: From<T>, [src]
impl<T, U> Into for T where
U: From<T>, impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, type Owned = T
fn to_owned(&self) -> T[src]
fn to_owned(&self) -> TCreates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)[src]
fn clone_into(&self, target: &mut T)🔬 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]
impl<T, U> TryFrom for T where
T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>try_from)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized, [src]
impl<T> Borrow for T where
T: ?Sized, impl<T> BorrowMut for T where
T: ?Sized, [src]
impl<T> BorrowMut for T where
T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src]
fn borrow_mut(&mut self) -> &mut TMutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
impl<T, U> TryInto for T where
U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>try_from)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized, [src]
impl<T> Any for T where
T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src]
fn get_type_id(&self) -> TypeId🔬 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