-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
75 lines (50 loc) · 1.19 KB
/
main.c
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
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <string.h>
#include "pog_static_heap.h"
#include "pog_real_heap.h"
char* x;
#define STATIC_MEM_CAP 2048
uintptr_t static_mem[STATIC_MEM_CAP];
int main() {
pog_gc_init(&static_mem_ptrs, sizeof(static_mem));
pog_gc_mark_static(&x);
//pog_real_heap_init();
pog_static_heap_init();
x = pog_malloc(1);
DEBUG("%p\n", x);
pog_malloc(80);
pog_malloc(80);
pog_malloc(80);
char* a = pog_malloc(sizeof(char) * 5);
strcpy(a, "Hello");
printf("%s\n", a);
char* b = pog_malloc(sizeof(char) * 10);
strcpy(b, " world foo");
printf("%s\n", b);
char* c = pog_malloc(sizeof(char) * 2);
strcpy(c, "!\n");
printf("%s\n", c);
pog_debug();
pog_gc_collect();
pog_debug();
x = NULL;
pog_gc_collect();
pog_debug();
pog_squash();
pog_debug();
b = pog_realloc(b, sizeof(char) * 18);
strcpy(b + 8, "oo bar");
printf("%s\n", b);
pog_debug();
b = pog_realloc(b, sizeof(char) * 10);
strcpy(b, " world foo");
printf("%s\n", b);
pog_debug();
pog_free(a);
pog_free(b);
pog_free(c);
pog_debug();
pog_squash();
pog_debug();
return 0;
}