Skip to content
CryoCryo home
Stdliballoc

heap

import std::alloc::heap; · source

alloc::heap is the library's own process heap: a segment allocator that maps its memory straight from the OS. It is what GlobalAllocator is backed by when a build sets [low_level] native_alloc, and NativeHeap names it directly, so a container can keep its storage there whatever GlobalAllocator is backed by.

All memory lives in 4 MiB, 4 MiB-aligned mappings ("segments"), so the segment that owns any block is found by masking the block's address — freeing never needs the caller to supply a size. Small requests are served from about forty size classes on a 16-byte granule, one class per segment, from a free list of returned blocks and then a bump frontier over unused space; a segment whose last block comes back is unmapped, so memory returns to the OS at once. Large or over-aligned requests get a mapping of their own. One global spinlock guards the metadata, so every allocating thread contends for the same lock. Freeing a pointer the heap never produced aborts with a message rather than corrupting its metadata.

Types

NativeHeap

type struct NativeHeap {}

A handle to the mmap-backed heap, holding no state. Every instance draws on the one process heap, so a block may be released through any of them. Its Allocator implementation lives in alloc::allocator, because allocator imports this module and the module graph rejects cycles.

import std::alloc::heap::{ NativeHeap };
import std::collections::array::{ Array };

mut xs: Array<i64, NativeHeap> = Array::<i64, NativeHeap>::new_in(NativeHeap::new());
xs.push(1);

Constructors

static new() -> NativeHeap;

A handle to the process's mmap-backed heap. Holds no state.

Trait implementations

implement trait Allocator for struct NativeHeap
std::alloc::allocator