cbase 1.50.0
C/C++ Static Template
Loading...
Searching...
No Matches
mem_arena.c File Reference

Implementation of the Virtual Memory Linear (Arena) Allocator. More...

#include "memory/mem_arena.h"
#include "memory/mem_allocator.h"
#include "memory/mem_os.h"
#include <string.h>
Include dependency graph for mem_arena.c:

Go to the source code of this file.

Macros

#define MEM_ARENA_COMMIT_SIZE   KB(64)

Functions

static void * mem_arena_push_internal (MemArena *arena, usize size, usize alignment)
MemArena mem_arena_create (usize reserve_size)
 Initializes a new virtual memory Arena.
void mem_arena_release (MemArena *arena)
 Returns all virtual memory back to the operating system.
void * mem_arena_push (MemArena *arena, usize size)
 Allocates bytes sequentially on the arena without zeroing.
void * mem_arena_push_zero (MemArena *arena, usize size)
 Allocates bytes and explicitly zero-initializes them.
void * mem_arena_push_aligned (MemArena *arena, usize size, usize alignment)
 Allocates bytes with a specific custom alignment.
void mem_arena_pop_to (MemArena *arena, usize pos)
 Rewinds the arena's pointer to a specific offset.
void mem_arena_clear (MemArena *arena)
 Resets the arena pointer to zero, freeing all allocations in O(1).
void mem_arena_clear_and_decommit (MemArena *arena)
 Clears the arena and returns all committed physical RAM to the OS.
char * mem_arena_push_cstr (MemArena *arena, const char *str, usize len)
 Copies a C string into the arena and appends a NUL terminator.
MemArenaTemp mem_arena_temp_begin (MemArena *arena)
 Temporary Memory API.
void mem_arena_temp_end (MemArenaTemp temp)
 Restores the arena to the position saved in temp.
static void * mem_arena_alloc_impl (MemAllocMode mode, void *ctx, usize size, void *old_ptr)
 Generic Allocator Interface Implementation.
MemAllocator mem_arena_allocator (MemArena *arena)
 Wraps a MemArena in the generic MemAllocator interface.

Detailed Description

Implementation of the Virtual Memory Linear (Arena) Allocator.

Definition in file mem_arena.c.

Macro Definition Documentation

◆ MEM_ARENA_COMMIT_SIZE

#define MEM_ARENA_COMMIT_SIZE   KB(64)

Definition at line 13 of file mem_arena.c.

Function Documentation

◆ mem_arena_alloc_impl()

void * mem_arena_alloc_impl ( MemAllocMode mode,
void * ctx,
usize size,
void * old_ptr )
static

Generic Allocator Interface Implementation.

Definition at line 149 of file mem_arena.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mem_arena_push_internal()

void * mem_arena_push_internal ( MemArena * arena,
usize size,
usize alignment )
static

Definition at line 16 of file mem_arena.c.