This commit is contained in:
2025-12-03 21:58:26 +01:00
parent 9214b986ac
commit f2e9bf2f83
2 changed files with 43 additions and 12 deletions
+2 -11
View File
@@ -6,7 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
typedef union any_align { char c; int i; long l; long long ll; float f; double d; void *p; } any_align_t;
typedef union any_align { char c; int i; long l; long long ll; float f; double d; void *p; long double ld; } any_align_t;
#define MAX_ALIGN ((size_t) sizeof(any_align_t))
#define KB (1024)
#define MB (KB * KB)
@@ -14,7 +14,6 @@ typedef union any_align { char c; int i; long l; long long ll; float f; double d
#define OFFSET(STRUCT, FIELD) ((size_t) (&((STRUCT*) NULL)->FIELD))
#define PTR_FROM_FIELD_PTR(STRUCT, FIELD, PTR) ((STRUCT *) (((char *) PTR) - OFFSET(STRUCT, FIELD)))
// Contains all operations an allocator can do. Similar interface to sdtlibs
// malloc, realloc and free.
typedef struct allocator_vtbl {
@@ -89,15 +88,7 @@ typedef struct arena_allocator {
allocator_t allocator;
size_t size;
size_t capacity;
// this may grow outside the allocated data. When data is not large enough,
// the backing allocator will be used to allocate exactly what the user
// asked for, and the total_allocated will grow for each such allocation.
// On the next reset if total_allocated is larger than capacity, we know
// that there are allocations outside the large buffer, so we reset the
// allocator, and allocate a new buffer that is the size of
// total_allocated, and set the new size of the capacity. Otherwise the
// size is just reset to 0. plus something else I think I forgot.
size_t total_allocated_bytes;
size_t bytes_outside_data;
uint8_t *data;
} arena_allocator_t;