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>
impl<A: Allocator + Clone> ChainAllocator<A>
Sourcepub const CHAIN_NODE_OVERHEAD: usize
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.
Sourcepub const fn new_in(chunk_size_hint: usize, allocator: A) -> Self
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.
Sourcepub fn used_bytes(&self) -> usize
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.
Sourcepub fn reserved_bytes(&self) -> usize
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.
Sourcepub fn remaining_capacity(&self) -> usize
pub fn remaining_capacity(&self) -> usize
Gets the number of bytes that can be allocated without requesting more from the underlying allocator.
Sourcepub fn has_capacity_for(&self, layout: Layout) -> bool
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>
impl<A: Allocator + Clone> Allocator for ChainAllocator<A>
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout)
unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout)
ptr. Read moreSource§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocate, but also ensures that the returned memory is zero-initialized. Read moreSource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
grow, but also ensures that the new contents are set to zero before being
returned. Read more