Graphviz 13.1.3~dev.20250813.2319
Loading...
Searching...
No Matches
arena.h File Reference

Region-based memory allocator. More...

#include <stdalign.h>
#include <stddef.h>
#include <util/api.h>
Include dependency graph for arena.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  arena_t
 

Macros

#define ARENA_NEW(arena, type)    gv_arena_alloc((arena), alignof(type), sizeof(type))
 

Typedefs

typedef struct arena_chunk arena_chunk_t
 

Functions

UTIL_API void * gv_arena_alloc (arena_t *arena, size_t alignment, size_t size)
 
UTIL_API char * gv_arena_strdup (arena_t *arena, const char *s)
 
UTIL_API void gv_arena_free (arena_t *arena, void *ptr, size_t size)
 
UTIL_API void gv_arena_reset (arena_t *arena)
 

Detailed Description

The API below is for interacting with a basic bump-pointer allocator.¹

¹ https://en.wikipedia.org/wiki/Region-based_memory_management

Definition in file arena.h.

Macro Definition Documentation

◆ ARENA_NEW

#define ARENA_NEW (   arena,
  type 
)     gv_arena_alloc((arena), alignof(type), sizeof(type))

allocate new memory for a typed value

This is shorthand for when you are allocating memory for a specific type. The returned memory is zero initialized.

Parameters
arenaArena to allocate from
typeType of value that will be later stored in this memory
Returns
Pointer to allocated memory

Definition at line 55 of file arena.h.

Typedef Documentation

◆ arena_chunk_t

typedef struct arena_chunk arena_chunk_t

a block of backing memory

This is a private implementation detail and should not be used outside of arena.c

Definition at line 22 of file arena.h.

Function Documentation

◆ gv_arena_alloc()

UTIL_API void * gv_arena_alloc ( arena_t arena,
size_t  alignment,
size_t  size 
)

allocate new memory

The requested alignment must be a power of two. The returned memory is zero initialized.

Parameters
arenaArena to allocate from
alignmentRequired pointer alignment for the resulting allocation
sizeNumber of bytes requested
Returns
Pointer to allocated memory

Definition at line 116 of file arena.c.

References alloc(), more_core(), and NULL.

Referenced by eval(), exprintf(), exsplit(), exstralloc(), exsubstr(), extoken_fn(), extokens(), getdyn(), gv_arena_strdup(), prformat(), scformat(), str_add(), str_and(), str_ior(), str_mod(), str_mpy(), and str_xor().

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

◆ gv_arena_free()

UTIL_API void gv_arena_free ( arena_t arena,
void *  ptr,
size_t  size 
)

deallocate memory

Parameters
arenaArena that was previously used to allocate this memory
ptrPointer to memory to release
sizeNumber of bytes of the original allocation

Definition at line 147 of file arena.c.

References ASAN_POISON, and NULL.

Referenced by prformat(), and scformat().

Here is the caller graph for this function:

◆ gv_arena_reset()

UTIL_API void gv_arena_reset ( arena_t arena)

deallocate all memory

Calling this restores the arena to an empty state from which it can be used for more allocations.

Parameters
arenaArena to reset

Definition at line 162 of file arena.c.

References free(), NULL, arena_chunk::previous, and arena_t::source.

Referenced by ELcleanup().

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

◆ gv_arena_strdup()

UTIL_API char * gv_arena_strdup ( arena_t arena,
const char *  s 
)

copy a string into new dynamic memory

Parameters
arenaArena to allocate from
sSource string to copy
Returns
A copy of the string, hosted in arena-allocated memory

Definition at line 134 of file arena.c.

References gv_arena_alloc(), len(), and NULL.

Referenced by eval(), exstring(), exsub(), extoken_fn(), and prformat().

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