Struct EspHeap

Source
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

Source

pub const fn empty() -> Self

Crate a new UNINITIALIZED heap allocator

Source

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 than start_addr

  • The size of the heap is (end_addr as usize) - (start_addr as usize). The allocator won’t use the byte at end_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.
Source

pub fn used(&self) -> usize

Returns an estimate of the amount of bytes in use in all memory regions.

Source

pub fn stats(&self) -> HeapStats

Return usage stats for the Heap.

Note: HeapStats directly implements [Display], so this function can be called from within println!() to pretty-print the usage of the heap.

Source

pub fn free(&self) -> usize

Returns an estimate of the amount of bytes available.

Source

pub fn free_caps(&self, capabilities: EnumSet<MemoryCapability>) -> usize

The free heap satisfying the given requirements

Source

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

Source§

unsafe fn alloc(&self, layout: Layout) -> *mut u8

Allocates memory as described by the given layout. Read more
Source§

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)

Deallocates the block of memory at the given ptr pointer with the given layout. Read more
1.28.0§

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8

Behaves like alloc, but also ensures that the contents are set to zero before being returned. Read more
1.28.0§

unsafe fn realloc( &self, ptr: *mut u8, layout: Layout, new_size: usize, ) -> *mut u8

Shrinks or grows a block of memory to the given new_size in bytes. The block is described by the given ptr pointer and layout. Read more

Auto 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§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.