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

APIs for memory management, including custom allocators and arenas. More...

Collaboration diagram for Memory Management:

Macros

#define infix_malloc   malloc
 A macro that can be defined to override the default malloc function.
 
#define infix_calloc   calloc
 A macro that can be defined to override the default calloc function.
 
#define infix_realloc   realloc
 A macro that can be defined to override the default realloc function.
 
#define infix_free   free
 A macro that can be defined to override the default free function.
 
#define infix_memcpy   memcpy
 A macro that can be defined to override the default memcpy function.
 
#define infix_memset   memset
 A macro that can be defined to override the default memset function.
 

Functions

c23_nodiscard infix_arena_tinfix_arena_create (size_t)
 Creates a new memory arena.
 
void infix_arena_destroy (infix_arena_t *)
 Destroys an arena and frees all memory allocated from it.
 
c23_nodiscard void * infix_arena_alloc (infix_arena_t *, size_t, size_t)
 Allocates a block of memory from an arena.
 
c23_nodiscard void * infix_arena_calloc (infix_arena_t *, size_t, size_t, size_t)
 Allocates and zero-initializes a block of memory from an arena.
 

Detailed Description

APIs for memory management, including custom allocators and arenas.

Macro Definition Documentation

◆ infix_calloc

#define infix_calloc   calloc

A macro that can be defined to override the default calloc function.

◆ infix_free

#define infix_free   free

A macro that can be defined to override the default free function.

◆ infix_malloc

#define infix_malloc   malloc

A macro that can be defined to override the default malloc function.

If you need to integrate infix with a custom memory allocator (e.g., for memory tracking or garbage collection), define this macro before including infix.h. You must also define the other infix_* memory macros.

#define infix_malloc my_custom_malloc
#define infix_calloc my_custom_calloc
#define infix_free my_custom_free
#define infix_realloc my_custom_realloc
#include <infix/infix.h>
The public interface for the infix FFI library.

◆ infix_memcpy

#define infix_memcpy   memcpy

A macro that can be defined to override the default memcpy function.

◆ infix_memset

#define infix_memset   memset

A macro that can be defined to override the default memset function.

◆ infix_realloc

#define infix_realloc   realloc

A macro that can be defined to override the default realloc function.

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 an arena.

Parameters
[in]arenaThe arena to allocate from.
[in]sizeThe number of bytes to allocate.
[in]alignmentThe required alignment for the allocation. 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 and zero-initializes a block of memory from an arena.

Parameters
[in]arenaThe arena to allocate from.
[in]numThe number of elements.
[in]sizeThe size of each element.
[in]alignmentThe required alignment. Must be a power of two.
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 a new memory arena.

An arena is a fast, region-based allocator. All objects allocated from it are freed at once when the arena is destroyed. This is the required mechanism for creating types for the Manual API.

Parameters
[in]initial_sizeThe initial capacity of the arena in bytes.
Returns
A pointer to the new arena, or nullptr on failure. The caller must free this with infix_arena_destroy.

◆ infix_arena_destroy()

void infix_arena_destroy ( infix_arena_t arena)

Destroys an arena and frees all memory allocated from it.

Parameters
[in]arenaThe arena to destroy. Safe to call with nullptr.