Skip to main content

Heap

Struct Heap 

Source
pub struct Heap { /* private fields */ }
Expand description

A handle to a mimalloc heap.

Allocations from a heap can be freed from any thread. Dropping a Heap moves its live blocks to the main heap (via mi_heap_delete).

Implementations§

Source§

impl Heap

Source

pub fn new() -> Option<Self>

Create a new heap. Returns None on OOM.

Source

pub fn new_in_arena(arena_id: ArenaId) -> Option<Self>

Create a heap that allocates exclusively from the given arena.

Source

pub fn main() -> Self

Get the main heap.

Source

pub unsafe fn heap_of(ptr: *const u8) -> Option<Self>

Get the heap that owns ptr.

§Safety

ptr must be a valid mimalloc-allocated pointer.

Source

pub unsafe fn contains(&self, ptr: *const u8) -> bool

Check if this heap contains ptr.

§Safety

ptr must be valid.

Source

pub unsafe fn malloc(&self, size: usize) -> *mut u8

Allocate size bytes from this heap.

§Safety

The returned pointer must be freed with mi_free (cross-heap frees are allowed).

Source

pub unsafe fn zalloc(&self, size: usize) -> *mut u8

Allocate zero-initialized memory from this heap.

§Safety

The returned pointer must be freed with mi_free.

Source

pub unsafe fn malloc_aligned(&self, size: usize, alignment: usize) -> *mut u8

Allocate aligned memory from this heap.

§Safety

The returned pointer must be freed with mi_free.

Source

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

Reallocate memory from this heap.

§Safety

ptr must be a valid mimalloc pointer. The returned pointer must be freed with mi_free.

Source

pub fn delete(self)

Delete this heap, moving live blocks to the main heap. Consumes self without running Drop. Borrowed heap handles are left untouched.

Source

pub unsafe fn destroy(self)

Destroy this heap, freeing all live blocks.

§Safety

All pointers from this heap become dangling. Borrowed heap handles are left untouched.

Source

pub fn collect(&self, force: bool)

Force garbage collection on this heap.

Source

pub fn stats_json(&self) -> String

Allocation statistics for this heap as JSON. Returns empty string on failure.

Source

pub fn stats_print(&self) -> String

Allocation statistics for this heap in mimalloc’s human-readable text format.

Source

pub fn as_ptr(&self) -> *mut mi_heap_t

Raw pointer to the underlying mi_heap_t.

Trait Implementations§

Source§

impl Drop for Heap

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Heap

Source§

impl Sync for Heap

Auto Trait Implementations§

§

impl Freeze for Heap

§

impl RefUnwindSafe for Heap

§

impl Unpin for Heap

§

impl UnsafeUnpin for Heap

§

impl UnwindSafe for Heap

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 = !

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.