infix
A JIT-Powered FFI Library for C
|
The arena allocator and configurable memory functions. More...
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_t * | infix_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. | |
The arena allocator and configurable memory functions.
#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
.
#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
.
#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.
#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
.
#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
.
#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
.
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.
arena | The arena to allocate from. |
size | The number of bytes to allocate. |
alignment | The required alignment of the returned pointer (must be a power of two). |
nullptr
on failure. 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.
arena | The arena to allocate from. |
num | The number of elements to allocate. |
size | The size of each element. |
alignment | The required alignment of the returned pointer. |
nullptr
on failure. c23_nodiscard infix_arena_t * infix_arena_create | ( | size_t | initial_size | ) |
Creates and initializes a new memory arena.
initial_size | The total number of bytes to pre-allocate for the arena. |
infix_arena_t
, or nullptr
if allocation fails. void infix_arena_destroy | ( | infix_arena_t * | arena | ) |
Frees an entire memory arena and all objects allocated within it.
arena | The arena to destroy. Can be nullptr (no-op). |