pub struct RegionManager<const N: usize> { /* private fields */ }Expand description
Static multi-region memory manager backed by an address-ordered first-fit free list per region.
Manages a fixed compile-time count N of non-overlapping memory regions without heap-allocated
bookkeeping or per-allocation headers. Regions are ordered from highest-priority / fastest
(0) to lowest-priority / largest (N - 1).
When large_allocation_threshold is Some(threshold), allocations smaller than threshold
probe regions in forward order (0..N) and allocations >= threshold probe in reverse order
((0..N).rev()), falling back across the remaining capable regions if the preferred region
is uninitialized, lacks a requested capability, violates DMA alignment, or is full.
Allocation and deallocation can access free lists in any managed region. Perform those operations while all registered regions are accessible.
Implementations§
Source§impl<const N: usize> RegionManager<N>
impl<const N: usize> RegionManager<N>
Sourcepub const fn new(
descriptors: [RegionDescriptor; N],
large_allocation_threshold: Option<usize>,
) -> RegionManager<N>
pub const fn new( descriptors: [RegionDescriptor; N], large_allocation_threshold: Option<usize>, ) -> RegionManager<N>
Creates a new uninitialized multi-region manager from static descriptors.
Sourcepub unsafe fn init_region(
&self,
index: usize,
start: *mut u8,
size: usize,
) -> bool
pub unsafe fn init_region( &self, index: usize, start: *mut u8, size: usize, ) -> bool
Initializes region index with [start, start + size).
Returns false if start is null or size is too small for allocator metadata,
leaving the region uninitialized.
§Panics
Panics if index >= N or if region index has already been initialized.
§Safety
For a non-null start, the caller must ensure that [start, start + size) is valid, unaliased, writable memory
for 'static, and does not overlap any other region managed by this instance.
Sourcepub fn init_region_from_slice(
&self,
index: usize,
slice: &'static mut [MaybeUninit<u8>],
) -> bool
pub fn init_region_from_slice( &self, index: usize, slice: &'static mut [MaybeUninit<u8>], ) -> bool
Initializes region index from a static mutable slice.
§Panics
Panics if index >= N or if region index has already been initialized.
Sourcepub fn is_region_initialized(&self, index: usize) -> bool
pub fn is_region_initialized(&self, index: usize) -> bool
Returns whether region index has been initialized.
Sourcepub fn region_contains(&self, index: usize, pointer: NonNull<u8>) -> bool
pub fn region_contains(&self, index: usize, pointer: NonNull<u8>) -> bool
Returns whether pointer falls within initialized region index’s address range.
Sourcepub fn get_free_for_capabilities(&self, capabilities: CapabilityFlags) -> usize
pub fn get_free_for_capabilities(&self, capabilities: CapabilityFlags) -> usize
Returns total free bytes across initialized regions advertising capabilities.
This does not account for layout constraints or fragmentation.
Sourcepub fn get_statistics(&self) -> Statistics<N>
pub fn get_statistics(&self) -> Statistics<N>
Returns per-region and aggregate heap statistics.
Trait Implementations§
Source§impl<const N: usize> ManagerTrait for RegionManager<N>
impl<const N: usize> ManagerTrait for RegionManager<N>
Source§unsafe fn reallocate(
&self,
capabilities: CapabilityFlags,
old_pointer: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Option<NonNull<u8>>
unsafe fn reallocate( &self, capabilities: CapabilityFlags, old_pointer: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Option<NonNull<u8>>
Resizes a block, in place when possible.
A compatible shrink keeps the pointer and returns the freed tail to the region. Growth below the large-allocation threshold tries the original region first. At or above the threshold, regions are tried in reverse order, as for allocation. Each candidate must meet the original capabilities and the new layout, including any DMA requirements.
The copy of a moved block runs outside the critical section.