pub struct Heap<'brand, P, B = MemoryBackendWrapper>{ /* private fields */ }Expand description
A scoped, lifetime-branded memory heap.
Heap is the single public heap surface. It statically validates local
block ownership through the scoped brand lifetime while delegating all
allocation mechanics to the monomorphized RawHeap core.
Implementations§
Source§impl<'brand, P, B> Heap<'brand, P, B>
impl<'brand, P, B> Heap<'brand, P, B>
Sourcepub fn alloc<Permit>(
&self,
_permit: Permit,
layout: Layout,
) -> Option<BrandedBlock<'brand, u8>>where
Permit: ReadPermit<'brand>,
pub fn alloc<Permit>(
&self,
_permit: Permit,
layout: Layout,
) -> Option<BrandedBlock<'brand, u8>>where
Permit: ReadPermit<'brand>,
Allocates a block of memory from this heap.
The block is tied to the heap’s unique 'brand lifetime. Returns None
if the allocation fails. The read permit proves that the request belongs
to this brand without adding runtime state.
Sourcepub fn free<T, Permit>(
&self,
_permit: &mut Permit,
block: BrandedBlock<'brand, T>,
)
pub fn free<T, Permit>( &self, _permit: &mut Permit, block: BrandedBlock<'brand, T>, )
Frees a block of memory back to this heap, dropping the value in-place first.
Because the block is branded with the heap’s unique 'brand lifetime,
it is statically guaranteed to have been allocated by this heap. The
write permit proves exclusive access while the value is dropped.
The block is returned to the heap even if T’s destructor panics.
Sourcepub fn free_uninit<T, Permit>(
&self,
_permit: &mut Permit,
block: BrandedBlock<'brand, T>,
)
pub fn free_uninit<T, Permit>( &self, _permit: &mut Permit, block: BrandedBlock<'brand, T>, )
Frees a block of memory back to this heap without dropping the value.
Useful for uninitialized memory or manual drop management.
Sourcepub fn alloc_init<T, Permit>(
&self,
permit: Permit,
val: T,
) -> Option<BrandedBlock<'brand, T>>where
Permit: ReadPermit<'brand>,
pub fn alloc_init<T, Permit>(
&self,
permit: Permit,
val: T,
) -> Option<BrandedBlock<'brand, T>>where
Permit: ReadPermit<'brand>,
Allocates and initializes a value directly in a branded memory block.
The block is guaranteed to contain a fully initialized value of type T.
Sourcepub fn realloc<T, Permit>(
&self,
permit: &mut Permit,
block: BrandedBlock<'brand, T>,
layout: Layout,
new_size: usize,
) -> Result<Option<BrandedBlock<'brand, u8>>, ReallocError<'brand, T>>
pub fn realloc<T, Permit>( &self, permit: &mut Permit, block: BrandedBlock<'brand, T>, layout: Layout, new_size: usize, ) -> Result<Option<BrandedBlock<'brand, u8>>, ReallocError<'brand, T>>
Reallocates a memory block from this heap.
The source block is returned inside ReallocError when the requested
layout is invalid or replacement allocation fails, so failure does not
leak or invalidate the original allocation. A new_size of zero frees
the source block and returns Ok(None). layout must describe the
source allocation; the boundary rejects sizes beyond the allocator’s
usable capacity and source-pointer alignment mismatches.
§Errors
Returns ReallocError with the original source block when the new
layout is invalid or replacement allocation fails.