Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using tcmalloc in my C++ project

Tags:

c++

tcmalloc

I'm linking my C++ program to tcmalloc with -ltcmalloc_minimal in linux and i have install the ltcmalloc lib with apt-get install libgoogle-perftools-dev.

Do i need to add any include file to my project source files to enable tcmalloc in my project? Do tcmalloc replaces all the new/free/malloc in all libs used by my project?

like image 318
Cristofer Martins Avatar asked Oct 14 '17 02:10

Cristofer Martins


1 Answers

Unless you specifically call tcmalloc API - i.e tc_new, tc_free You don't need to include any headers from tcmalloc. This is because malloc and other memory functions declarations are already included by the call to include <malloc.h>. Their definitions are overridden(or aliased) in tcmalloc library. In TCMalloc, the standard API (new, malloc, realloc, free, delete, etc...) and also POSIX API (such as posix_memaligned) are either aliased (in GCC compatible platforms) or overridden (windows, ...). The only thing you need to add is in case of static linkage the libraries -ltcmalloc_minimal.a or -ltcmalloc.a and it's path.

like image 153
Daniel Heilper Avatar answered Oct 27 '22 09:10

Daniel Heilper