Using tcmalloc in my C++ project
Asked Answered
P

3

7

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?

Perusal answered 14/10, 2017 at 2:10 Comment(0)
S
2

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.

Stanger answered 7/5, 2018 at 12:9 Comment(0)
M
0

Yes you need to include the headers because you need the declarations for the functions.

For your second question, I would suggest you read their documentation

Mb answered 14/10, 2017 at 2:15 Comment(1)
That documentation does not answer my question.Perusal
P
0

To close this question, i just needed to include the lib in the compiling process, no need to include any header.

Perusal answered 18/7, 2018 at 1:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.