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_addrmust 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
'staticlifetime). - 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 Allocator for EspHeap
impl Allocator for EspHeap
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
ptr. Read moreSource§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocate, but also ensures that the returned memory is zero-initialized. Read moreSource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
grow, but also ensures that the new contents are set to zero before being
returned. Read moreSource§impl Allocator for EspHeap
Available on crate feature nightly only.
impl Allocator for EspHeap
nightly only.Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, CoreAllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, CoreAllocError>
allocator_api)Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
allocator_api)ptr. Read moreSource§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api)allocate, but also ensures that the returned memory is zero-initialized. Read moreSource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
allocator_api)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 more