Subastra
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Data Fields
arena_t Struct Reference

The Arena allocator is a single continous block of memory. More...

#include <arena.h>

Collaboration diagram for arena_t:
Collaboration graph
[legend]

Public Member Functions

#define arena_alloc_ty(ty, arena, sz)   (ty *)arena_alloc(arena, sz * sizeof(ty))
 Allocate a typed array inside the arena.
 

Static Public Member Functions

static void arena_init (arena_t *arena, allocator_t fallback, sz size)
 Initializes the memory arena.
 
static void arena_clear (arena_t *arena)
 Clears the memory arena entirely and marks all the memory as poison. Importantly, does not release memory. O(1)
 
static void arena_cleanup (arena_t *arena)
 Release all the allocated memory.
 
static allocator_t arena_as_allocator (arena_t *arena)
 A generic function to type-erase the arena_t into an allocator_t.
 

Data Fields

allocator_t fallback
 The allocator that the arena will forward all the allocation requests to.
 
byteroot
 The starting address of the arena.
 
sz size
 The total amount of bytes the arena can handle.
 
sz offset
 The next location to put the data at.
 

Detailed Description

The Arena allocator is a single continous block of memory.

Any deletions from the block do nothing except mark the memory as poisoned. The intention to use the arena for objects that share a lifetime, for instance all objects that live for 1 frame.

Member Function Documentation

◆ arena_as_allocator()

static allocator_t arena_as_allocator ( arena_t arena)
static

A generic function to type-erase the arena_t into an allocator_t.

◆ arena_cleanup()

static void arena_cleanup ( arena_t arena)
static

Release all the allocated memory.

◆ arena_clear()

static void arena_clear ( arena_t arena)
static

Clears the memory arena entirely and marks all the memory as poison. Importantly, does not release memory. O(1)

◆ arena_init()

static void arena_init ( arena_t arena,
allocator_t  fallback,
sz  size 
)
static

Initializes the memory arena.

Field Documentation

◆ fallback

allocator_t fallback

The allocator that the arena will forward all the allocation requests to.

◆ offset

sz offset

The next location to put the data at.

◆ root

byte* root

The starting address of the arena.

◆ size

sz size

The total amount of bytes the arena can handle.