Sturk 1.1.0
Publish-subscribe C implementation.
Loading...
Searching...
No Matches
arena.h File Reference

Arena allocator. More...

#include <stddef.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  StArenaGroup
 Collection of arena instances. More...
 

Macros

#define ST_ARENA_ALLOC(arena, size)    st_arena_alloc((arena), (size), __FILE__, __LINE__)
 Allocate memory from an arena.
 

Typedefs

typedef struct StArena StArena
 The arena.
 

Functions

StArenast_arena_create (struct StArenaGroup *group, void *(*alloc_cb)(size_t), void(*free_cb)(void *))
 Create an arena.
 
void st_arena_destroy (StArena *arena)
 Destroy an arena.
 
void * st_arena_alloc (StArena *arena, size_t size, const char *file, int line)
 Allocate memory from an arena.
 
void st_arena_free (StArena *arena)
 Free all the memory allocated from a single arena.
 
void st_arena_cleanup (struct StArenaGroup *group)
 Free all the memory from an arena collection.
 

Detailed Description

Arena allocator.

Solution inspired by the example from "C Interfaces and Implementations: Techniques for Creating Reusable Software" by David Hanson.

Function Documentation

◆ st_arena_alloc()

void * st_arena_alloc ( StArena arena,
size_t  size,
const char *  file,
int  line 
)

Allocate memory from an arena.

Parameters
[in,out]arenaThe pointer to the arena.
[in,out]sizeThe size in bytes of the requested memory.
[in]fileThe path to the calling source file.
[in]lineThe number of the calling line of code from the source file.
Returns
The pointer to the allocated memory.

◆ st_arena_cleanup()

void st_arena_cleanup ( struct StArenaGroup group)

Free all the memory from an arena collection.

Parameters
[in,out]groupThe arena collection.

◆ st_arena_create()

StArena * st_arena_create ( struct StArenaGroup group,
void *(*)(size_t)  alloc,
void(*)(void *)  free 
)

Create an arena.

Parameters
[in,out]groupCollection of arena instances.
[in]allocMemory allocation callback.
[in]freeMemory freeing callback.
Returns
The pointer to the new arena.

◆ st_arena_destroy()

void st_arena_destroy ( StArena arena)

Destroy an arena.

Parameters
[in,out]arenaThe pointer to the arena.

◆ st_arena_free()

void st_arena_free ( StArena arena)

Free all the memory allocated from a single arena.

Parameters
[in,out]arenaThe pointer to the arena.