[go: up one dir, main page]

Menu

[e222c1]: / utils / malloc.cpp  Maximize  Restore  History

Download this file

48 lines (42 with data), 1.6 kB

 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
#include <iostream>
#include <malloc.h>
#include <stdlib.h>
#include "../common/utils.h"
using namespace std;
void print_malloc_stats()
{
struct mallinfo info = mallinfo();
STXXL_MSG("MALLOC statistics BEGIN")
STXXL_MSG("===============================================================")
STXXL_MSG("non-mmapped space allocated from system (bytes): "<<info.arena)
STXXL_MSG("number of free chunks : "<<info.ordblks)
STXXL_MSG("number of fastbin blocks : "<<info.smblks)
STXXL_MSG("number of chunks allocated via mmap() : "<<info.hblks)
STXXL_MSG("total number of bytes allocated via mmap() : "<<info.hblkhd)
STXXL_MSG("maximum total allocated space (bytes) : "<<info.usmblks)
STXXL_MSG("space available in freed fastbin blocks (bytes): "<<info.fsmblks)
STXXL_MSG("number of bytes allocated and in use : "<<info.uordblks)
STXXL_MSG("number of bytes allocated but not in use : "<<info.fordblks)
STXXL_MSG("top-most, releasable (via malloc_trim) space : "<<info.keepcost)
STXXL_MSG("================================================================")
};
int main(int argc, char * argv[])
{
if(argc < 2)
{
cerr << "Usage: "<<argv[0]<<" bytes_to_allocate"<<endl;
return -1;
}
sbrk(128*1024*1024);
cout << "Nothing allocated" << endl;
print_malloc_stats();
char tmp;
cin >> tmp;
const unsigned bytes = atoi(argv[1]);
char * ptr = new char[bytes];
cout << "Allocated " << bytes << " bytes" << endl;
print_malloc_stats();
delete [] ptr;
cout << "Deallocated " << endl;
print_malloc_stats();
};