Skip to content
Try Kata

mem.allocator

Allocation interface and the interpreter-backed heap allocator.

All modules · Writing docstrings

type Allocator

Allocate, grow, and release raw storage measured in value slots.

Source, line 4

func make(self, cap: Int): RawPtr

Allocate cap slots.

Source, line 6

func grow(self, raw: RawPtr, old_cap: Int, new_cap: Int): RawPtr

Move old_cap slots into a new allocation and release the old one.

Source, line 8

func free(self, raw: RawPtr)

Release a live allocation.

Source, line 10

kind HeapAllocator

An allocator implemented with the interpreter’s raw memory intrinsics.

Source, line 14

impl HeapAllocator as Allocator

Source, line 16

func make(self, cap: Int): RawPtr

Allocate cap value slots through mem.alloc.

Source, line 18

func grow(self, raw: RawPtr, old_cap: Int, new_cap: Int): RawPtr

Allocate new storage, copy old_cap slots, and free raw. Requires new_cap >= old_cap.

Source, line 23

func free(self, raw: RawPtr)

Free the allocation through mem.free; later access to the handle is invalid.

Source, line 37

let heap = HeapAllocator {}

The shared heap allocator value. Import with import mem.{heap}.

Source, line 43