allocators/core

sourceallocators/core.sx

Arena

pub type Arena = { buf: ref void, offset: usize, cap: usize }

Fields

NameType
bufref void
offsetusize
capusize

AllocError

pub enum AllocError = { OutOfMemory }

Variants

  • OutOfMemory

new

pub fn (Arena) new(capacity: usize) result[Allocator, AllocError] = trust { ... }

free

pub fn (Arena) free(arena: mut Arena) void = trust { ... }

alloc

pub fn (Arena) alloc(arena: Arena, size: usize) option[ref void]

used

pub fn (Arena) used(arena: Arena) usize

cap

pub fn (Arena) cap(arena: Arena) usize

remaining

pub fn (Arena) remaining(arena: Arena) usize

reset

pub fn (Arena) reset(arena: Arena) void = trust { ... }

Stack

type Stack = { buf: ref void, offset: usize, cap: usize }

Fields

NameType
bufref void
offsetusize
capusize

new

pub fn (Stack) new(capacity: usize) result[Allocator, AllocError] = trust { ... }

alloc

pub fn (Stack) alloc(stack: Stack, size: usize) option[ref void]

save

pub fn (Stack) save(stack: Stack) usize

restore

pub fn (Stack) restore(stack: Stack, checkpoint: usize) void

free

pub fn (Stack) free(stack: mut Stack) void = trust { ... }

HeapAllocator

pub type HeapAllocator = {  }

alloc

pub fn (HeapAllocator) alloc(_: HeapAllocator, size: usize) option[ref void] = trust { ... }

free

pub fn (HeapAllocator) free(_: HeapAllocator, ptr: ref void) void = trust { ... }

realloc

pub fn (HeapAllocator) realloc(_: HeapAllocator, ptr: ref void, new_size: usize) option[ref void] = trust { ... }

bump_alloc_unwrap

pub fn bump_alloc_unwrap[A: Allocator](ac: A, size: usize) ref void

alloc_in

pub fn alloc_in[A: GeneralAllocator](ac: A, size: usize) option[ref void]

free_in

pub fn free_in[A: GeneralAllocator](ac: A, ptr: ref void) void

realloc_in

pub fn realloc_in[A: GeneralAllocator](ac: A, ptr: ref void, new_size: usize) option[ref void]