ChainAllocator

Struct ChainAllocator 

Source
pub struct ChainAllocator<A: Allocator + Clone> { /* private fields */ }
Expand description

ChainAllocator is an arena allocator, meaning that deallocating individual allocations made by this allocator does nothing. Instead, the whole backing memory is dropped at once. Destructors for these objects are not called automatically and must be done by the caller if it’s necessary.

ChainAllocator creates a new LinearAllocator when the current one doesn’t have enough space for the requested allocation, and then links the new LinearAllocator to the previous one, creating a chain. This is where its name comes from.

Implementations§

Source§

impl<A: Allocator + Clone> ChainAllocator<A>

Source

pub const CHAIN_NODE_OVERHEAD: usize

The amount of bytes used by the ChainAllocator at the start of each chunk of the chain for bookkeeping.

Source

pub const fn new_in(chunk_size_hint: usize, allocator: A) -> Self

Creates a new ChainAllocator. The chunk_size_hint is used as a size hint when creating new chunks of the chain. Note that the ChainAllocator will use some bytes at the beginning of each chunk of the chain. The number of bytes is Self::CHAIN_NODE_OVERHEAD. Keep this in mind when sizing your hint if you are trying to be precise, such as making sure a specific object fits.

Source

pub fn used_bytes(&self) -> usize

Get the number of bytes allocated, including bytes for overhead. It does not count space it could allocate still, such as unused space at the end of the top node in the chain. It does count unallocated space at the end of previous nodes in the chain.

Source

pub fn reserved_bytes(&self) -> usize

Get the number of bytes allocated by the underlying allocators for this chain. This number is greater than or equal to Self::used_bytes.

Source

pub fn remaining_capacity(&self) -> usize

Gets the number of bytes that can be allocated without requesting more from the underlying allocator.

Source

pub fn has_capacity_for(&self, layout: Layout) -> bool

Can the requested layout be allocated without requesting more from the underlying allocator.

Trait Implementations§

Source§

impl<A: Allocator + Clone> Allocator for ChainAllocator<A>

Source§

fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>

Attempts to allocate a block of memory. Read more
Source§

unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout)

Deallocates the memory referenced by ptr. Read more
Source§

fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>

Behaves like allocate, but also ensures that the returned memory is zero-initialized. Read more
Source§

unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>

Attempts to extend the memory block. Read more
Source§

unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>

Behaves like grow, but also ensures that the new contents are set to zero before being returned. Read more
Source§

unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>

Attempts to shrink the memory block. Read more
Source§

fn by_ref(&self) -> &Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Allocator. Read more
Source§

impl<A: Allocator + Clone> Drop for ChainAllocator<A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<A: Allocator + Clone> Send for ChainAllocator<A>

Auto Trait Implementations§

§

impl<A> !Freeze for ChainAllocator<A>

§

impl<A> !RefUnwindSafe for ChainAllocator<A>

§

impl<A> !Sync for ChainAllocator<A>

§

impl<A> Unpin for ChainAllocator<A>
where A: Unpin,

§

impl<A> !UnwindSafe for ChainAllocator<A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.