55 if (
arena ==
nullptr) {
88 while (current !=
nullptr) {
118 if (
arena ==
nullptr)
121 if (alignment == 0 || (alignment & (alignment - 1)) != 0) {
128 if (current_block->
error)
133 if (aligned_offset < current_block->current_offset) {
134 current_block->
error =
true;
139 if (SIZE_MAX - size >= aligned_offset && aligned_offset + size <= current_block->capacity) {
140 void * ptr = current_block->
buffer + aligned_offset;
150 size_t next_size = current_block->
block_size * 2;
151 if (next_size < size + alignment)
152 next_size = size + alignment;
155 current_block->
error =
true;
181 if (size > 0 && num > SIZE_MAX / size) {
187 size_t total_size = num * size;
190 memset(ptr, 0, total_size);
infix_arena_t * arena
Definition 005_layouts.c:60
#define c23_nodiscard
A compatibility macro for the C23 [[nodiscard]] attribute.
Definition compat_c23.h:106
@ INFIX_CODE_INTEGER_OVERFLOW
Definition infix.h:1236
@ INFIX_CODE_UNKNOWN
Definition infix.h:1226
@ INFIX_CODE_OUT_OF_MEMORY
Definition infix.h:1228
@ INFIX_CATEGORY_ALLOCATION
Definition infix.h:1216
@ INFIX_CATEGORY_GENERAL
Definition infix.h:1215
#define infix_free
A macro that can be defined to override the default free function.
Definition infix.h:301
void infix_arena_destroy(infix_arena_t *arena)
Destroys an arena and frees all memory allocated from it.
Definition arena.c:83
#define infix_calloc
A macro that can be defined to override the default calloc function.
Definition infix.h:293
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.
Definition arena.c:179
c23_nodiscard void * infix_arena_alloc(infix_arena_t *arena, size_t size, size_t alignment)
Allocates a block of memory from an arena.
Definition arena.c:117
c23_nodiscard infix_arena_t * infix_arena_create(size_t initial_size)
Creates a new memory arena.
Definition arena.c:52
Internal data structures, function prototypes, and constants.
void _infix_set_error(infix_error_category_t category, infix_error_code_t code, size_t position)
Sets the thread-local error state with detailed information.
Definition error.c:165
static size_t _infix_align_up(size_t value, size_t alignment)
Aligns a value up to the next multiple of a power-of-two alignment.
Definition infix_internals.h:727
Internal definition of a memory arena.
Definition infix_internals.h:138
char * buffer
Definition infix_internals.h:139
bool error
Definition infix_internals.h:142
size_t capacity
Definition infix_internals.h:140
size_t block_size
Definition infix_internals.h:144
size_t current_offset
Definition infix_internals.h:141
struct infix_arena_t * next_block
Definition infix_internals.h:143