aboutsummaryrefslogtreecommitdiff
path: root/memory.h
blob: 38e632a5901f2f5a3f2c45bf0c7d3e9dd76f5ed9 (plain) (blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef memory_h
#define memory_h

int aligned(void* p, int a);
int align_size(int s, int a);

typedef struct Arena {
	char* buf;
	int size, ptr;
} Arena;

void init_arena(
	Arena* a,
	void* mem,
	int size
);
void clear_arena(Arena* a);
void* arena_alloc(
	Arena* a,
	int size
);
void* arena_alloc_aligned(
	Arena* a,
	int size,
	int align
);

typedef struct Heap {
	char* buf;
	int size, blocks;
} Heap;

void init_heap(
	Heap* h,
	void* mem,
	int size
);
void* heap_alloc(
	Heap* h,
	int size
);
void* heap_alloc_aligned(
	Heap* h,
	int size,
	int align
);
void heap_free_aligned(
	Heap* h,
	void* p
);
void heap_free(
	Heap* h,
	void* p
);
void heap_defrag(Heap* h);
#endif