diff options
Diffstat (limited to 'teensy/teensy_mem.h')
| -rw-r--r-- | teensy/teensy_mem.h | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/teensy/teensy_mem.h b/teensy/teensy_mem.h index 133869f..b4cdc62 100644 --- a/teensy/teensy_mem.h +++ b/teensy/teensy_mem.h @@ -1,11 +1,37 @@ #ifndef TEENSY_MEM_H_ #define TEENSY_MEM_H_ +#include <stdint.h> #include <stdlib.h> #define ty_new(T) (ty_alloc(sizeof(T))) -void ty_free_temp_allocs(void); +// A specific section of memory allocated for an arena. +typedef struct Arena_Hunk Arena_Hunk; +struct Arena_Hunk { + Arena_Hunk *next; + uint8_t *start; + uint8_t *end; + uint8_t *head; +}; + +// Memory arena. It allows the user of this API to allocate lots of memory and +// free it all at once. Arenas do not support reallocation. +typedef struct { + Arena_Hunk *hunks; + size_t hunk_size; + size_t alloced_size; +} Arena; + +// Makes an allocation with the speicified arena. +void *ty_arena_alloc(Arena *arena, size_t size); +// Frees all allocations made with this arena. +void ty_arena_clear(Arena *arena); +// Frees the arena itself. Do NOT call to free allocations made with the arena. +// Use `ty_arena_clear()` for that. +void ty_arena_free(Arena *arena); + +void ty_clear_temp_allocs(void); // Temp allocation. Freed at the end of every frame. Do NOT realloc. void *ty_talloc(size_t size); |
