pub struct StackAllocator<const N: usize> { /* private fields */ }Expand description
A simple bump‑allocator that lives on the stack (or in static memory).
It will tries to reuse freed memory only if it is the most recently allocated block.
N is the size of the backing buffer in bytes.
Implementations§
Source§impl<const N: usize> StackAllocator<N>
impl<const N: usize> StackAllocator<N>
Trait Implementations§
Source§impl<const N: usize> Allocator for StackAllocator<N>
impl<const N: usize> Allocator for StackAllocator<N>
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Attempts to allocate a block of memory. Read more
Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
🔬This is a nightly-only experimental API. (
allocator_api)Deallocates the memory referenced by
ptr. 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>
🔬This is a nightly-only experimental API. (
allocator_api)Attempts to extend the memory block. Read more
Source§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Attempts to shrink the memory block. Read more
Source§fn by_ref(&self) -> &Selfwhere
Self: Sized,
fn by_ref(&self) -> &Selfwhere
Self: Sized,
🔬This is a nightly-only experimental API. (
allocator_api)Creates a “by reference” adapter for this instance of
Allocator. Read moreSource§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Behaves like
allocate, but also ensures that the returned memory is zero-initialized. Read moreSource§impl<const N: usize> Default for StackAllocator<N>
impl<const N: usize> Default for StackAllocator<N>
impl<const N: usize> Send for StackAllocator<N>
impl<const N: usize> Sync for StackAllocator<N>
Auto Trait Implementations§
impl<const N: usize> !Freeze for StackAllocator<N>
impl<const N: usize> !RefUnwindSafe for StackAllocator<N>
impl<const N: usize> Unpin for StackAllocator<N>
impl<const N: usize> UnwindSafe for StackAllocator<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more