Memory
Arena
Arena - A
bump allocator that keeps allocations stable until the arena is
destroyed.
Members: Arena, ~Arena, take, allocate, allocateValue
allocate
Allocator -
A (possibly stateful) memory allocator: allocation and deallocation
function pointers plus an opaque state pointer passed to both. Function
pointers instead of an interface because interfaces cannot be stored in
variables.
Members: state, alloc, free
Context
- The ambient context: settings implicitly used by the standard
library.
Members: allocator
context -
Returns the caller's ambient context. This is a compiler intrinsic:
direct calls read the hidden context parameter. The body only runs for
indirect calls, which cannot provide a context and abort.
defaultAllocator
- Returns the default allocator, which allocates with malloc and frees
with free.
withAllocator
- Runs body with the given allocator installed in the
ambient context.
allocate
- Allocates uninitialized storage for count values and
returns a pointer to it.
tryAllocate
- Allocates uninitialized storage for count values and
returns a pointer to it.
allocateValue
- Moves the given value into newly allocated dynamic memory and returns
a pointer to it.
tryAllocateValue
- Moves the given value into newly allocated dynamic memory and returns
a pointer to it.
deallocate -
Deallocates a block of dynamic memory that was previously allocated by a
call to allocate, tryAllocate,
allocateValue, or tryAllocateValue.
drop
drop - Ends the
lifetime of the given value immediately, running its destructor (if
any).
take
takeFrom -
Moves the value out of the given slot, leaving defaultValue
in its place.