remove the free function entirely. all allocators are now expected to
implement reset instead. I reallized I never ever want to free an
individual allocation ever again. The forever_allocator is a special
case wherEreset is a no-op. The arena allocator was deleted. It will be
replaced soon.
This commit is contained in:
2025-12-02 20:21:12 +01:00
parent ef8d51f153
commit 01b8150625
11 changed files with 62 additions and 385 deletions
+9 -16
View File
@@ -1,34 +1,27 @@
#include "cig.h"
static void *stdlib_alloc(void *this, size_t bytes, const char *file, int line) {
static void *forever_alloc(void *this, size_t bytes) {
(void)this;
(void)file;
(void)line;
return malloc(bytes);
}
static void *stdlib_resize(void *this, void *old_ptr, size_t bytes, const char *file, int line) {
static void *forever_resize(void *this, void *old_ptr, size_t bytes) {
(void)this;
(void)file;
(void)line;
return realloc(old_ptr, bytes);
}
static void stdlib_free(void *this, void *ptr, const char *file, int line) {
static void forever_no_op(void *this) {
(void)this;
(void)file;
(void)line;
free(ptr);
}
static const allocator_vtbl_t stdlib_vtbl = {
.alloc = stdlib_alloc,
.resize = stdlib_resize,
.free = stdlib_free,
static const allocator_vtbl_t forever_vtbl = {
.alloc = forever_alloc,
.resize = forever_resize,
.reset = forever_no_op,
};
allocator_t allocator_stdlib() {
allocator_t forever_allocator() {
return (allocator_t) {
.this=NULL,
.vtbl=&stdlib_vtbl,
.vtbl=&forever_vtbl,
};
}