refactor
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:
+9
-16
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user