​ptmalloc​​ 是glibc的内存分配管理

​tcmalloc​​ 是google的内存分配管理模块

​jemalloc​​ 是BSD的提供的内存分配管理

写一段代码测试一下

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
extern "C"
{
#include "jemalloc.h"
}
#include <map>
#include <string>
using namespace std;
int main()
{
char *buff = new char[32];
lab_beg:
clock_t begin = clock();
int i = 0;
for(i=0;i<10000000;i++)
{
char *buff = (char *)malloc(1024);
}
map<int, string> map_container;
for(int i=0;i<1000000;i++)
{
map_container.insert(make_pair(i, "hello world"));
}
printf("%d new char[1024] costs:%f s\n", i, (double)(clock()-begin)/CLOCKS_PER_SEC);
getchar();
goto lab_beg;
}


INCLUDE=
LIB_PATH=
LIBS=
FLAGS=-D_Debug -Wl,-Bstatic -DJEMALLOC_NO_RENAME
CXXFALGS=

test:test.cpp
g++ -g test.cpp -o test -I./

test_je:test.cpp
g++ -g test.cpp -o test_je -I./ -lgcc_s -L./ -ljemalloc

test_tc:test.cpp
g++ -g test.cpp -o test_tc -L../../gpertools-2.1/.libs -ltcmalloc

clean:
rm -f test


结果好像差别不大,jemalloc的结果不知道为何出不来了。。。

c++内存管理优化之ptmalloc,tcmalloc,jemalloc使用实例_#include