infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
Memory Management

The arena allocator and configurable memory functions. More...

Collaboration diagram for Memory Management:

Files

file  arena.c
 Implementation of the internal arena allocator.
 

Macros

#define infix_malloc   malloc
 A macro for the memory allocation function used by the library.
 
#define infix_calloc   calloc
 A macro for the zero-initializing memory allocation function.
 
#define infix_realloc   realloc
 A macro for the memory reallocation function.
 
#define infix_free   free
 A macro for the memory deallocation function.
 
#define infix_memcpy   memcpy
 A macro for copying memory from a source to a destination pointer.
 
#define infix_memset   memset
 A macro for setting a block of memory to a specific value.
 

Functions

c23_nodiscard infix_arena_tinfix_arena_create (size_t)
 Creates and initializes a new memory arena.
 
void infix_arena_destroy (infix_arena_t *)
 Frees an entire memory arena and all objects allocated within it.
 
c23_nodiscard void * infix_arena_alloc (infix_arena_t *, size_t, size_t)
 Allocates a block of memory from the arena with a specific alignment.
 
c23_nodiscard void * infix_arena_calloc (infix_arena_t *, size_t, size_t, size_t)
 Allocates a zero-initialized block of memory from the arena.
 

Detailed Description

The arena allocator and configurable memory functions.

Macro Definition Documentation

◆ infix_calloc

#define infix_calloc   calloc

A macro for the zero-initializing memory allocation function.

Defaults to calloc. Can be overridden for custom memory management. See the example under infix_malloc.

◆ infix_free

#define infix_free   free

A macro for the memory deallocation function.

Defaults to free. Can be overridden for custom memory management. See the example under infix_malloc.

◆ infix_malloc

#define infix_malloc   malloc

A macro for the memory allocation function used by the library.

By default, this maps to the standard malloc. Users can define this macro before including infix.h to redirect all internal memory allocations to a custom allocator, for example, for memory pooling, leak tracking, or integration with a garbage collector.

◆ infix_memcpy

#define infix_memcpy   memcpy

A macro for copying memory from a source to a destination pointer.

Defaults to memcpy. Can be overridden for custom memory management. See the example under infix_malloc.

◆ infix_memset

#define infix_memset   memset

A macro for setting a block of memory to a specific value.

Defaults to memset. Can be overridden for custom memory management. See the example under infix_malloc.

◆ infix_realloc

#define infix_realloc   realloc

A macro for the memory reallocation function.

Defaults to realloc. Can be overridden for custom memory management. See the example under infix_malloc.

Function Documentation

◆ infix_arena_alloc()

c23_nodiscard void * infix_arena_alloc ( infix_arena_t arena,
size_t  size,
size_t  alignment 
)

Allocates a block of memory from the arena with a specific alignment.

Parameters
arenaThe arena to allocate from.
sizeThe number of bytes to allocate.
alignmentThe required alignment of the returned pointer (must be a power of two).
Returns
A pointer to the allocated memory, or nullptr on failure.

◆ infix_arena_calloc()

c23_nodiscard void * infix_arena_calloc ( infix_arena_t arena,
size_t  num,
size_t  size,
size_t  alignment 
)

Allocates a zero-initialized block of memory from the arena.

Parameters
arenaThe arena to allocate from.
numThe number of elements to allocate.
sizeThe size of each element.
alignmentThe required alignment of the returned pointer.
Returns
A pointer to the zero-initialized memory, or nullptr on failure.

◆ infix_arena_create()

c23_nodiscard infix_arena_t * infix_arena_create ( size_t  initial_size)

Creates and initializes a new memory arena.

Parameters
initial_sizeThe total number of bytes to pre-allocate for the arena.
Returns
A pointer to the new infix_arena_t, or nullptr if allocation fails.

◆ infix_arena_destroy()

void infix_arena_destroy ( infix_arena_t arena)

Frees an entire memory arena and all objects allocated within it.

Parameters
arenaThe arena to destroy. Can be nullptr (no-op).