Created
September 11, 2010 14:38
-
-
Save ghisguth/575236 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
#include <string> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <iostream> | |
#include <vector> | |
#include <sys/mman.h> | |
#include <unistd.h> | |
int main(int argc, char** argv) | |
{ | |
if(argc > 1) | |
{ | |
std::cout<<"sbrk. press any key...\n"; | |
std::getchar(); | |
std::cout<<"sbrk(0)="<<sbrk(0)<<"\n"; | |
void * pp = mmap(sbrk(0), 4096, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); | |
std::cout<<"mmap=>"<<pp<<"\n"; | |
} | |
std::cout<<"ready? press any key...\n"; | |
std::getchar(); | |
void * p0 = malloc(16); | |
std::cout<<"p\'="<<p0<<"\n"; | |
free(p0); | |
p0 = 0; | |
std::vector<void*> chunks; | |
for(int i = 0; i < 2048; ++i) | |
{ | |
size_t len = 1*1024*1024; | |
void * p = malloc(1*1024*1024); | |
std::fill(reinterpret_cast<char*>(p), reinterpret_cast<char*>(p) + len, 0x01); | |
std::cout<<"p["<<i<<"]="<<p<<"\n"; | |
chunks.push_back(p); | |
} | |
std::cout<<"use [pmap `pgrep a.out`] and press any key...\n"; | |
std::getchar(); | |
for(std::vector<void*>::iterator it = chunks.begin(); it != chunks.end(); ++it) | |
{ | |
free(*it); | |
} | |
chunks.clear(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment