summaryrefslogtreecommitdiff
path: root/qstd/memory.h
blob: a0b819a71de71ebc9d8dacc5fc5d78cff49b2891 (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
57
58
59
60
61
62
63
#ifndef memory_h
#define memory_h

#include <stddef.h>
#include <stdint.h>

int aligned(const void* p, int a);
int align_size(int s, int a);
uintptr_t align_address(uintptr_t ad, size_t al);

void zero(void* buf, int size);

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);
int heap_block_size(void* ptr);
#endif