88 int *val = (
int *)
mem_alloc(&ally,
sizeof(
int));
96 usize old_size =
sizeof(int) * 4;
97 usize new_size =
sizeof(int) * 8;
98 int *old_arr = (
int *)
mem_alloc(&ally, old_size);
103 int *grown = (
int *)
mem_realloc(&ally, old_arr, old_size, new_size);
function void mem_free(MemAllocator *alloc, void *ptr, usize size)
Frees a previously allocated block through the allocator.
function void * mem_alloc(MemAllocator *alloc, usize size)
Allocator Helper Functions.
function void * mem_realloc(MemAllocator *alloc, void *old_ptr, usize old_size, usize new_size)
Resizes a previously allocated block through the allocator.
void mem_arena_clear(MemArena *arena)
Resets the arena pointer to zero, freeing all allocations in O(1).
void mem_arena_temp_end(MemArenaTemp temp)
Restores the arena to the position saved in temp.
void mem_arena_release(MemArena *arena)
Returns all virtual memory back to the operating system.
#define PUSH_ARRAY(arena, type, count)
Pushes an array of structs of type T onto the arena.
void * mem_arena_push(MemArena *arena, usize size)
Allocates bytes sequentially on the arena without zeroing.
#define PUSH_STRUCT(arena, type)
Type-Safe Allocation Macros.
#define PUSH_ARRAY_ALIGNED(arena, type, count, alignment)
Pushes an array of structs with custom memory alignment.
struct MemAllocator mem_arena_allocator(MemArena *arena)
Wraps a MemArena in the generic MemAllocator interface.
MemArenaTemp mem_arena_temp_begin(MemArena *arena)
Temporary Memory API.
MemArena mem_arena_create(usize reserve_size)
Initializes a new virtual memory Arena.
Generic interface for abstracting memory allocators.
High-performance virtual memory Arena Allocator.
An abstract allocator interface.
A virtual memory-backed linear allocator.
A temporary snapshot of an arena's state.
Single-header testing framework with pretty-printed output.
#define EXPECT(cond)
Evaluates a condition. Records and counts the failure if false.
#define TEST_CASE(name)
Declares a test case function.
#define EXPECT_FATAL(cond)
Like EXPECT but aborts immediately on failure.