forked from cloudflare/luajit-mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.c
55 lines (45 loc) · 1.27 KB
/
demo.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
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include "lj_mm.h"
/* TODO: this demo is junk, we need better demo... */
static void*
mmap_wrap(size_t len) {
return lm_mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_32BIT | MAP_PRIVATE, -1, 0);
}
int
main(int argc, char** argv) {
#if defined(DEBUG)
lm_init();
dump_page_alloc(stderr);
int size1 = 100;
char* p1 = mmap_wrap(size1);
fprintf(stderr, "\nsize=%d, %p\n", size1, p1);
dump_page_alloc(stderr);
int size2 = 4097;
char* p2 = mmap_wrap(size2);
fprintf(stderr, "\nsize=%d, %p\n", size2, p2);
dump_page_alloc(stderr);
int size3 = 4097;
char* p3 = mmap_wrap(size3);
fprintf(stderr, "\nsize=%d %p\n", size3, p3);
dump_page_alloc(stderr);
int size4 = 4096 * 3;
char* p4 = mmap_wrap(size4);
fprintf(stderr, "\nsize=%d %p\n", size4, p4);
dump_page_alloc(stderr);
int size5 = 4096 * 2;
char* p5 = mmap_wrap(size5);
fprintf(stderr, "\nsize=%d %p\n", size5, p5);
dump_page_alloc(stderr);
lm_munmap(p1, size1);
lm_munmap(p2, size2);
lm_munmap(p3, size3);
lm_munmap(p4, size4);
lm_munmap(p5, size5);
fprintf(stderr, "\n\nAfter delete all allocations\n");
dump_page_alloc(stderr);
/*lm_fini(); */
#endif
return 0;
}