Skip to main content

RegionManager

Struct RegionManager 

Source
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>

Source

pub const fn new( descriptors: [RegionDescriptor; N], large_allocation_threshold: Option<usize>, ) -> Self

Creates a new uninitialized multi-region manager from static descriptors.

Source

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.

Source

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.

Source

pub fn is_region_initialized(&self, index: usize) -> bool

Returns whether region index has been initialized.

Source

pub fn region_contains(&self, index: usize, pointer: NonNull<u8>) -> bool

Returns whether pointer falls within initialized region index’s address range.

Source

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.

Source

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>

Source§

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.

Source§

unsafe fn allocate( &self, capabilities: CapabilityFlags, layout: Layout, ) -> Option<NonNull<u8>>

Allocates memory with the specified capabilities and layout. Read more
Source§

unsafe fn deallocate(&self, pointer: NonNull<u8>, layout: Layout)

Deallocates memory previously allocated by this allocator. Read more
Source§

fn get_used(&self) -> usize

Returns the amount of memory currently used in this allocator. Read more
Source§

fn get_free(&self) -> usize

Returns the amount of memory currently available in this allocator. Read more
Source§

fn get_total_size(&self) -> usize

Returns the total size of the memory managed by this allocator. Read more
Source§

fn flush_instruction_cache(&self, _address: NonNull<u8>, _size: usize)

Flushes the instruction cache for a specific memory region. Read more
Source§

fn flush_data_cache(&self)

Flushes the data cache to ensure memory coherency. Read more
Source§

fn get_page_size(&self) -> usize

Returns the page size used by this memory allocator. Read more

Auto Trait Implementations§

§

impl<const N: usize> !Freeze for RegionManager<N>

§

impl<const N: usize> !RefUnwindSafe for RegionManager<N>

§

impl<const N: usize> Send for RegionManager<N>

§

impl<const N: usize> Sync for RegionManager<N>

§

impl<const N: usize> Unpin for RegionManager<N>

§

impl<const N: usize> UnsafeUnpin for RegionManager<N>

§

impl<const N: usize> UnwindSafe for RegionManager<N>

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.