pub struct LinearAllocator<A: Allocator> { /* private fields */ }Expand description
LinearAllocator 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.
Once the slice of memory that underpins the LinearAllocator has been allocated, allocations will begin to fail. It will not find new memory to back allocations.
Implementations§
Source§impl<A: Allocator> LinearAllocator<A>
impl<A: Allocator> LinearAllocator<A>
Sourcepub fn new_in(layout: Layout, allocator: A) -> Result<Self, AllocError>
pub fn new_in(layout: Layout, allocator: A) -> Result<Self, AllocError>
Creates a new LinearAllocator by requesting the layout from the
provided allocator. Note that if the allocation is over-sized,
meaning it’s larger than the requested layout.size(), then the
LinearAllocator will utilize this excess.
Sourcepub fn used_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
Get the number of bytes allocated.
Sourcepub fn reserved_bytes(&self) -> usize
pub fn reserved_bytes(&self) -> usize
Get the number of bytes allocated by the underlying allocator. 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
Determine if the given layout will fit in the current allocator
Trait Implementations§
Source§impl<A: Allocator> Allocator for LinearAllocator<A>
impl<A: Allocator> Allocator for LinearAllocator<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