diff options
Diffstat (limited to 'src/arena.h')
| -rw-r--r-- | src/arena.h | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/src/arena.h b/src/arena.h deleted file mode 100644 index 907a2fa..0000000 --- a/src/arena.h +++ /dev/null | |||
| @@ -1,41 +0,0 @@ | |||
| 1 | #ifndef __VXGG_REWRITE___ARENA_H___25077218513438___ | ||
| 2 | #define __VXGG_REWRITE___ARENA_H___25077218513438___ | ||
| 3 | |||
| 4 | #include <stddef.h> | ||
| 5 | |||
| 6 | // Normal arena. Can expand in size beyond original allocation | ||
| 7 | typedef struct arena arena; | ||
| 8 | |||
| 9 | // A wrapper for the normal arena struct. Can not expand in size | ||
| 10 | typedef arena simplearena; | ||
| 11 | |||
| 12 | // Bitwise operation to check if a number is a power of 2 | ||
| 13 | #define ISPOWOF2(x) (((x) & ((x) - 1)) == 0) | ||
| 14 | |||
| 15 | // Variable for memory alignment | ||
| 16 | static const size_t MEM_ALIGN_BYTES = (2 * sizeof(void*)); | ||
| 17 | |||
| 18 | // Macro to get the remaining bytes necessary to be on a power of 2 | ||
| 19 | #define MEM_ALIGN(x) ((x) + (((x) & (MEM_ALIGN_BYTES - 1)) != 0) * (MEM_ALIGN_BYTES - ((x) & (MEM_ALIGN_BYTES - 1)))) | ||
| 20 | |||
| 21 | |||
| 22 | // Initialize an arena with `bytes` bytes of pre-allocated memory. Exits / returns NULL on error depending on the value of `___VXGG___USE_XALLOC_FOR_ARENAS___` | ||
| 23 | arena * arena_init(size_t bytes); | ||
| 24 | |||
| 25 | // Take `bytes` bytes of memory from `arena`'s memory pool. Exits / returns NULL on error depending on the value of `___VXGG___USE_XALLOC_FOR_ARENAS___` | ||
| 26 | void * arena_alloc(arena * const arena, size_t bytes); | ||
| 27 | |||
| 28 | // Free an arena its memory pool(s). Returns -1 and sets `errno` if the given arena is NULL | ||
| 29 | void arena_free(void *a); | ||
| 30 | |||
| 31 | |||
| 32 | // Initializes a simple arena. | ||
| 33 | simplearena * simplearena_init(size_t bytes); | ||
| 34 | |||
| 35 | // Grabs some memory from the simple arena's pool. Exits / returns NULL on error depending on the value of `___VXGG___USE_XALLOC_FOR_ARENAS___` | ||
| 36 | void * simplearena_alloc(simplearena * const a, size_t bytes); | ||
| 37 | |||
| 38 | // Free a simple arena. Exits / returns -1 on error depending on the value of `___VXGG___USE_XALLOC_FOR_ARENAS___` | ||
| 39 | void simplearena_free(simplearena *a); | ||
| 40 | |||
| 41 | #endif \ No newline at end of file | ||
