pub struct EspHeap { /* private fields */ }
Expand description
A memory allocator
In addition to what Rust’s memory allocator can do it allows to allocate memory in regions satisfying specific needs.
Implementations§
Source§impl EspHeap
impl EspHeap
Sourcepub unsafe fn add_region(&self, region: HeapRegion)
pub unsafe fn add_region(&self, region: HeapRegion)
Add a memory region to the heap
heap_bottom
is a pointer to the location of the bottom of the heap.
size
is the size of the heap in bytes.
You can add up to three regions per allocator.
Note that:
-
Memory is allocated from the first suitable memory region first
-
The heap grows “upwards”, towards larger addresses. Thus
end_addr
must be larger thanstart_addr
-
The size of the heap is
(end_addr as usize) - (start_addr as usize)
. The allocator won’t use the byte atend_addr
.
§Safety
- The supplied memory region must be available for the entire program (a
'static
lifetime). - The supplied memory region must be exclusively available to the heap only, no aliasing.
size > 0
.
Sourcepub fn used(&self) -> usize
pub fn used(&self) -> usize
Returns an estimate of the amount of bytes in use in all memory regions.
Sourcepub fn free_caps(&self, capabilities: EnumSet<MemoryCapability>) -> usize
pub fn free_caps(&self, capabilities: EnumSet<MemoryCapability>) -> usize
The free heap satisfying the given requirements
Sourcepub unsafe fn alloc_caps(
&self,
capabilities: EnumSet<MemoryCapability>,
layout: Layout,
) -> *mut u8
pub unsafe fn alloc_caps( &self, capabilities: EnumSet<MemoryCapability>, layout: Layout, ) -> *mut u8
Allocate memory in a region satisfying the given requirements.
§Safety
This function is unsafe because undefined behavior can result
if the caller does not ensure that layout
has non-zero size.
The allocated block of memory may or may not be initialized.
Trait Implementations§
Source§impl GlobalAlloc for EspHeap
impl GlobalAlloc for EspHeap
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
layout
. Read more1.28.0§unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
alloc
, but also ensures that the contents
are set to zero before being returned. Read more