Skip to main content

StackAlloc

Struct StackAlloc 

Source
pub struct StackAlloc<B: FixedRange> { /* private fields */ }
Expand description

LIFO-discipline allocator over a FixedRange backing.

Maintains a frame stack so nested alloc/free with arbitrary depth works correctly. Each allocate pushes the new frame’s offset; deallocate validates the supplied pointer matches the top of the stack and pops.

Implementations§

Source§

impl<B: FixedRange> StackAlloc<B>

Source

pub fn new(backing: B) -> Result<Self, AllocError>

Construct a LIFO allocator over backing’s entire range.

The frame stack starts at capacity 0 and grows on demand via the global allocator. For workloads with a known maximum nesting depth, prefer Self::with_max_depth to pre-reserve the frame stack and avoid heap reallocations on the alloc hot path.

Source

pub fn with_max_depth(backing: B, max_depth: usize) -> Result<Self, AllocError>

Construct with a hint for the maximum frame depth. The frame stack is pre-allocated with max_depth capacity, so the alloc hot path does not trigger a Vec grow / reallocation for the first max_depth nested allocations.

If max_depth is exceeded at runtime the Vec will grow normally — the constructor’s value is a hint, not a hard cap. Pass 0 for the same behavior as Self::new.

Source

pub fn allocated(&self) -> usize

Bytes currently in use.

Source

pub fn remaining(&self) -> usize

Bytes remaining.

Source

pub fn backing(&self) -> &B

Borrow the backing.

Trait Implementations§

Source§

impl<B: FixedRange> Allocator for StackAlloc<B>

Source§

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

Allocate a block satisfying layout. The returned slice’s length is at least layout.size() but may be larger.
Source§

fn capacity_bytes(&self) -> Option<usize>

Total bytes this allocator can issue, if bounded. None for unbounded allocators like System. Used by Watermark to compute thresholds.
Source§

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

Allocate a zero-initialized block.
Source§

unsafe fn grow( &self, ptr: NonNull<u8>, old: NonZeroLayout, new: NonZeroLayout, ) -> Result<NonNull<[u8]>, AllocError>

Grow an allocation in place if possible, otherwise allocate-copy-free. Read more
Source§

unsafe fn shrink( &self, ptr: NonNull<u8>, old: NonZeroLayout, new: NonZeroLayout, ) -> Result<NonNull<[u8]>, AllocError>

Shrink an allocation in place if possible, otherwise allocate-copy-free. Read more
Source§

fn reset(&mut self) -> Result<(), AllocError>

Reclaim everything previously allocated. Default impl returns AllocError — only arena-style allocators implement a meaningful reset. Read more
Source§

unsafe fn usable_size( &self, _ptr: NonNull<u8>, _layout: NonZeroLayout, ) -> Option<usize>

Usable size of an existing allocation, if the allocator can report it. Defaults to None — implementors that track usable size override. Read more
Source§

fn corruption_events(&self) -> u64

Detected freelist / metadata corruption events observed by this allocator since construction. Read more
Source§

impl<B: FixedRange> Deallocator for StackAlloc<B>

Source§

unsafe fn deallocate(&self, ptr: NonNull<u8>, _layout: NonZeroLayout)

Release a previously allocated block. Read more
Source§

impl<B: FixedRange> FixedRange for StackAlloc<B>

Source§

fn base(&self) -> NonNull<u8>

First byte of the owned address range. Read more
Source§

fn size(&self) -> usize

Length in bytes of the owned address range. Read more
Source§

fn commit(&self, offset: usize, len: usize) -> Result<(), AllocError>

Ensure the bytes [offset, offset + len) (relative to base) are backed by committed, writable memory before a consumer writes through them. Read more
Source§

fn contains(&self, ptr: NonNull<u8>) -> bool

Whether ptr lies within [base, base + size). Read more

Auto Trait Implementations§

§

impl<B> !Freeze for StackAlloc<B>

§

impl<B> !RefUnwindSafe for StackAlloc<B>

§

impl<B> !Sync for StackAlloc<B>

§

impl<B> Send for StackAlloc<B>
where B: Send,

§

impl<B> Unpin for StackAlloc<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for StackAlloc<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for StackAlloc<B>
where B: UnwindSafe,

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.