-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathREADME
More file actions
34 lines (24 loc) · 755 Bytes
/
Copy pathREADME
File metadata and controls
34 lines (24 loc) · 755 Bytes
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
TINYHEAP
Simple, linked-list implementation of a heap in pure C.
See the tinyheap_config.h in the default/ folder for buildtime configurations.
To be used in an embedded environment with small ram.
Use the heap by doing something like this:
#include "tinyheap.h"
// use this space as heap
static char heap_space[4096];
// this is the heap metainfo
static tinyheap heap;
// initiate heap, do this at startup
void startup_heap_init(void) {
th_init(&heap, heap_space, sizeof(heap_space));
}
// use the heap
void use_heap(void) {
void *data = th_malloc(&heap, 100);
if (data == 0) {
.. out of memory ..
} else {
.. do something with those hundred bytes ..
th_free(&heap, data);
}
}