Heap
Source: std/heap.mw.
The allocator is size-class based and gets its pages from sys_mmap_anon. Nothing in it calls libc.
A small general-purpose allocator on top of raw pages (std/os.mw).
- Requests up to 64 KiB are rounded to a power-of-two size class
(16 B .. 64 KiB). Freed blocks go on a per-class free list.
- Larger requests get their own mapping, returned to the OS on free.
- Every block has a 16-byte header: word 0 = class index (or total
mapping size for large blocks), word 1 = -1 for large blocks, else 0.
Constants
Section titled “Constants”| Name | Type | Value | Notes |
|---|---|---|---|
HEAP_TABLE |
i64 |
0 |
|
HEAP_CUR |
i64 |
0 |
|
HEAP_END |
i64 |
0 |
Functions
Section titled “Functions”heap_word
Section titled “heap_word”fn heap_word(addr: i64) -> *i64heap_class
Section titled “heap_class”fn heap_class(size: i64) -> i64heap_class_size
Section titled “heap_class_size”fn heap_class_size(c: i64) -> i64Size in bytes of a size class: 16 * 2^c (the language has no shift operator).
heap_init
Section titled “heap_init”fn heap_init() -> i64heap_alloc
Section titled “heap_alloc”fn heap_alloc(size: i64) -> *u8heap_capacity
Section titled “heap_capacity”fn heap_capacity(ptr: *u8) -> i64heap_free
Section titled “heap_free”fn heap_free(ptr: *u8)heap_realloc
Section titled “heap_realloc”fn heap_realloc(ptr: *u8, new_size: i64) -> *u8heap_alloc_zeroed
Section titled “heap_alloc_zeroed”fn heap_alloc_zeroed(size: i64) -> *u8