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
impl Heap
Sourcepub fn new_in_arena(arena_id: ArenaId) -> Option<Self>
pub fn new_in_arena(arena_id: ArenaId) -> Option<Self>
Create a heap that allocates exclusively from the given arena.
Sourcepub unsafe fn malloc(&self, size: usize) -> *mut u8
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).
Sourcepub unsafe fn zalloc(&self, size: usize) -> *mut u8
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.
Sourcepub unsafe fn realloc(&self, ptr: *mut u8, new_size: usize) -> *mut u8
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.
Sourcepub fn delete(self)
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.
Sourcepub unsafe fn destroy(self)
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.
Sourcepub fn stats_json(&self) -> String
pub fn stats_json(&self) -> String
Allocation statistics for this heap as JSON. Returns empty string on failure.
Sourcepub fn stats_print(&self) -> String
pub fn stats_print(&self) -> String
Allocation statistics for this heap in mimalloc’s human-readable text format.