blob: bbfb8525888358603aac5334d6e409eb8d7e5969 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
/**
* @file mem.h
* @brief Allocators, memory tracking
* @version 0.1
* @date 2024-02-24
*
* @copyright Copyright (c) 2024
*
*/
#pragma once
#include <stddef.h>
// Inspired by https://nullprogram.com/blog/2023/09/27/
typedef struct arena {
char* begin;
char* curr;
char* end;
} arena;
typedef struct arena_save {
arena* arena;
char* savepoint;
} arena_save;
arena arena_create(void* backing_buffer, size_t capacity);
void* arena_alloc(arena* a, size_t size);
void* arena_alloc_align(arena* a, size_t size, size_t align);
void arena_free_all(arena* a);
void arena_free_storage(arena* a);
arena_save arena_savepoint(arena* a);
void arena_rewind(arena_save savepoint);
// TODO: arena_resize
|