-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.c
More file actions
41 lines (30 loc) · 912 Bytes
/
Copy pathnode.c
File metadata and controls
41 lines (30 loc) · 912 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
35
36
37
38
39
40
41
#include "node3.h"
#include <stdio.h>
/* Lists ram usage, the first value is the DATA size, so the
* sum of all allocated memory (allocated by the user). The
* second value in brackets is the total ram usage including
* the allocated memory size of the struct itself. */
#define LOG(number) \
printf("[%d] Total used mem: %lub (%lub)\n", number, \
node_alloc_total(group), node_mem_total(group))
int main(){
__mem *group = node_group();
// 1. Allocate string
char *msg = (char *)node_strdup(&group, "Hello World!");
printf("%s\n", msg);
// Should be the size of the above string
LOG(1);
// 2. Realloc those bytes to be exactly 16 bytes
msg = nrealloc(&group, msg, 16);
// Should be exactly 16 bytes
LOG(2);
// Allocate another 4 bytes to the pool
nalloc(&group, 4);
// 3. Goes up to 20
LOG(3);
// 4. Free ALL memory
nabsolve(&group);
// And back to zero
LOG(4);
return 0;
}