pub struct EspHeap { /* private fields */ }
Implementations§
source§impl EspHeap
impl EspHeap
sourcepub const fn empty() -> EspHeap
pub const fn empty() -> EspHeap
Crate a new UNINITIALIZED heap allocator
You must initialize this heap using the
init
method before using the
allocator.
sourcepub unsafe fn init(&self, heap_bottom: *mut u8, size: usize)
pub unsafe fn init(&self, heap_bottom: *mut u8, size: usize)
Initializes the heap
This function must be called BEFORE you run any code that makes use of the allocator.
heap_bottom
is a pointer to the location of the bottom of the heap.
size
is the size of the heap in bytes.
Note that:
-
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.
- This function must be called exactly ONCE.
size > 0
.
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>
🔬This is a nightly-only experimental API. (
allocator_api
)Attempts to allocate a block of memory. Read more
source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
🔬This is a nightly-only experimental API. (
allocator_api
)Deallocates the memory referenced by
ptr
. Read moresource§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api
)Behaves like
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>
🔬This is a nightly-only experimental API. (
allocator_api
)Attempts to extend the memory block. Read more
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>
🔬This is a nightly-only experimental API. (
allocator_api
)Behaves like
grow
, but also ensures that the new contents are set to zero before being
returned. Read moresource§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
Allocate memory as described by the given
layout
. Read moreAuto Trait Implementations§
impl !Freeze for EspHeap
impl !RefUnwindSafe for EspHeap
impl Send for EspHeap
impl Sync for EspHeap
impl Unpin for EspHeap
impl UnwindSafe for EspHeap
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more