aboutsummaryrefslogtreecommitdiff
path: root/allocator.h
diff options
context:
space:
mode:
Diffstat (limited to 'allocator.h')
-rw-r--r--allocator.h30
1 files changed, 0 insertions, 30 deletions
diff --git a/allocator.h b/allocator.h
deleted file mode 100644
index dd9bb16..0000000
--- a/allocator.h
+++ /dev/null
@@ -1,30 +0,0 @@
1#pragma once
2
3#include <stddef.h> /* size_t */
4
5struct allocator {
6 void *(*allocate)(struct allocator *allocator, size_t n);
7 void (*deallocate)(struct allocator *allocator, void *ptr);
8};
9
10extern struct allocator default_allocator;
11
12/* allocator interface */
13void *allocator_malloc(struct allocator *allocator, size_t n);
14void allocator_free(struct allocator *allocator, void *ptr);
15
16/* helper functions */
17char *allocator_strdup(struct allocator *allocator, const char *str);
18void *allocator_malloc_zero(struct allocator *allocator, size_t n);
19
20#define ALLOCATE(n) \
21 allocator_malloc(&allocator_default_allocator, (n))
22
23#define ALLOCATE_ZERO(n) \
24 allocator_malloc_zero(&allocator_default_allocator, (n))
25
26#define FREE(ptr) \
27 (allocator_free(&allocator_default_allocator, (ptr)), (ptr) = NULL)
28
29#define NEW(ptr) ((ptr) = ALLOCATE(sizeof *(ptr)))
30#define NEW0(ptr) ((ptr) = ALLOCATE_ZERO(sizeof *(ptr)))