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
76
77
78
79
80
81
82
83
84
85
86
87
|
#include <cstdio>
#include <cstdlib>
#define HAVE_ALIGNED_ALLOC defined(_ISOC11_SOURCE)
struct Foo
{
Foo()
: i(new int)
{
}
~Foo()
{
delete i;
}
int* i;
};
void asdf()
{
int* i = new int;
printf("i in asdf: %p\n", (void*)i);
}
void bar()
{
asdf();
}
void laaa()
{
bar();
}
void split()
{
Foo f;
asdf();
bar();
laaa();
}
static Foo foo;
int main()
{
Foo* f = new Foo;
printf("new Foo: %p\n", (void*)f);
delete f;
char* c = new char[1000];
printf("new char[]: %p\n", (void*)c);
delete[] c;
void* buf = malloc(100);
printf("malloc: %p\n", buf);
buf = realloc(buf, 200);
printf("realloc: %p\n", buf);
free(buf);
buf = calloc(5, 5);
printf("calloc: %p\n", buf);
cfree(buf);
#if HAVE_ALIGNED_ALLOC
buf = aligned_alloc(16, 160);
printf("aligned_alloc: %p\n", buf);
free(buf);
#endif
buf = valloc(32);
printf("valloc: %p\n", buf);
free(buf);
posix_memalign(&buf, 16, 64);
printf("posix_memalign: %p\n", buf);
free(buf);
for (int i = 0; i < 10; ++i) {
laaa();
}
laaa();
split();
return 0;
}
|