APIs for memory management, including custom allocators and arenas.
More...
|
| #define | infix_malloc(n) infix_allocator.malloc(n) |
| | A macro that can be defined to override infix's allocator at compile time.
|
| |
| #define | infix_calloc(nelem, size) infix_allocator.calloc(nelem, size) |
| | A macro that can be defined to override infix's allocator at compile time.
|
| |
| #define | infix_realloc(ptr, n) infix_allocator.realloc(ptr, n) |
| | A macro that can be defined to override infix's allocator at compile time.
|
| |
| #define | infix_free(ptr) infix_allocator.free(ptr) |
| | A macro that can be defined to override infix's allocator at compile time.
|
| |
| #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.
|
| |
APIs for memory management, including custom allocators and arenas.
◆ infix_calloc
| #define infix_calloc |
( |
|
nelem, |
|
|
|
size |
|
) |
| infix_allocator.calloc(nelem, size) |
A macro that can be defined to override infix's allocator at compile time.
◆ infix_free
A macro that can be defined to override infix's allocator at compile time.
◆ infix_malloc
| #define infix_malloc |
( |
|
n | ) |
infix_allocator.malloc(n) |
A macro that can be defined to override infix's allocator at compile time.
infix routes every internal heap allocation through the infix_malloc, infix_calloc, infix_realloc, and infix_free macros. By default they dispatch to the runtime allocator installed with infix_set_allocator().
If you prefer a compile-time override (no indirect call at all), define these macros before including infix.h. You must then define all four consistently, and anything that frees infix-owned memory must use infix_free.
#define infix_malloc my_custom_malloc
#define infix_calloc my_custom_calloc
#define infix_free my_custom_free
#define infix_realloc my_custom_realloc
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 |
( |
|
ptr, |
|
|
|
n |
|
) |
| infix_allocator.realloc(ptr, n) |
A macro that can be defined to override infix's allocator at compile time.
◆ infix_arena_alloc()
Allocates a block of memory from an arena.
- Parameters
-
| [in] | arena | The arena to allocate from. |
| [in] | size | The number of bytes to allocate. |
| [in] | alignment | The 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()
Allocates and zero-initializes a block of memory from an arena.
- Parameters
-
| [in] | arena | The arena to allocate from. |
| [in] | num | The number of elements. |
| [in] | size | The size of each element. |
| [in] | alignment | The required alignment. Must be a power of two. |
- Returns
- A pointer to the zero-initialized memory, or
nullptr on failure.
◆ infix_arena_create()
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_size | The 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()
Destroys an arena and frees all memory allocated from it.
- Parameters
-
| [in] | arena | The arena to destroy. Safe to call with nullptr. |
◆ infix_set_allocator()
Replaces the allocator infix uses for all internal heap allocations.
- Parameters
-
| [in] | allocator | A pointer to a valid infix_allocator_t, or NULL to restore the default C library allocator. |
infix copies the callback pointers, so the caller may pass a temporary struct. Call this before creating any trampolines (typically during host initialization) and before infix is used from more than one thread, since the table is not internally synchronized.
Every pointer infix returns must be freed through the same allocator: callers that release infix-owned memory (such as the buffer returned by emit_get_binary) must use infix_free or the equivalent entry point of the allocator they installed rather than the C library's free.
◆ infix_allocator
The allocator currently used for all of infix's internal heap allocations.
Initialized to the C library's malloc/calloc/realloc/free. Do not assign to it directly. Use infix_set_allocator() so the documentation and any future locking stay in one place.