-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
37 lines (35 loc) · 930 Bytes
/
test.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
#include <stdio.h>
#include <unistd.h>
#include "libxalloc.h"
#define SZ (256*1024*1024)
int main(int argc, char *argv[])
{
void *p0, *p1;
printf("brk init = %p\n", p0 = sbrk(0));
for (int i = 0; i < 7; i++) {
char *s0 = xmalloc(SZ);
for (int i = 0; i < SZ; i++) {
s0[i] = i%26 + 0x61;
}
char *s1 = xmalloc(SZ);
for (int i = 0; i < SZ; i++) {
s1[i] = i%26 + 0x61;
}
char *s2 = xmalloc(SZ);
for (int i = 0; i < SZ; i++) {
s2[i] = i%26 + 0x61;
}
char *s3 = xmalloc(SZ);
for (int i = 0; i < SZ; i++) {
s3[i] = i%26 + 0x61;
}
s3[26] = 0; printf("%d: %s\n", i, s3);
xfree(s0);
xfree(s1);
xfree(s2);
xfree(s3);
}
printf("brk exit = %p\n", p1 = sbrk(0));
printf("brk difference = %zu B\n", (size_t) (p1 - p0));
return 0;
}