Created
January 28, 2013 22:03
-
-
Save arisada/4659578 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* When mallocing a huge amount of data, you will be put directly in mmap */ | |
/* however, if you manage to alloc and desalloc blocks of data under 0x80000 */ | |
/* you will be able to change the threshold and have bigger blocks of data */ | |
/* alloced in the brk() heap. */ | |
aris@ubuntu1204-32:$ cat mesures.c | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
int main(){ | |
int i; | |
int len = 0x20000 * 4 - 10 * 4096 - 8; | |
char *ptr; | |
for(i=0;i<20;++i){ | |
malloc(i*100); | |
} | |
printf("Mallocing %d bytes\n", len); | |
for(i=0;i<3;++i){ | |
ptr=malloc(len); | |
printf("p: %p\n",ptr); | |
free(ptr); | |
} | |
len = 0x20000 * 4 - 8; | |
printf("Mallocing %d bytes\n", len); | |
for(i=0;i<3;++i){ | |
ptr=malloc(len); | |
printf("p: %p\n",ptr); | |
free(ptr); | |
} | |
len = 0x20000 * 4 + 10; | |
printf("Mallocing %d bytes\n", len); | |
for(i=0;i<3;++i){ | |
ptr=malloc(len); | |
printf("p: %p\n",ptr); | |
free(ptr); | |
} | |
return 0; | |
} | |
/* | |
aris@ubuntu1204-32:$ ./mesures | |
Mallocing 483320 bytes | |
p: 0xb74c8008 | |
p: 0x8c10ac0 | |
p: 0x8c10ac0 | |
Mallocing 524280 bytes | |
p: 0x8c10ac0 | |
p: 0x8c10ac0 | |
p: 0x8c10ac0 | |
Mallocing 524298 bytes | |
p: 0x8c10ac0 | |
p: 0x8c10ac0 | |
p: 0x8c10ac0 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment