c :: import "@ffi/c" Allocator :: struct { context ?*mut anyopaque alloc @func(context ?*mut anyopaque, size usize, alignment usize) ?*mut u8 free @func(context ?*mut anyopaque, memory ?*mut u8, size usize, alignment usize) void } heap Allocator :: Allocator { context = none, alloc = heap_alloc, free = heap_free, } heap_alloc func(context ?*mut anyopaque, size usize, alignment usize) ?*mut u8 { return ptr_cast(u8, c.malloc(size)) } heap_free func(context ?*mut anyopaque, memory ?*mut u8, size usize, alignment usize) void { c.free(memory) } alloc func(allocator Allocator, size usize, alignment usize) ?*mut u8 { return allocator.alloc(allocator.context, size, alignment) } free func(allocator Allocator, memory ?*mut u8, size usize, alignment usize) void { allocator.free(allocator.context, memory, size, alignment) }