How to use TCMalloc by it's header but not instead of malloc, new

117 views Asked by At

I'm adding TCMalloc to my project. My method is linking .a to my project, so all of malloc, new, free... will be replaced by implement of TCMalloc. But some of malloc in my project can't be replaced because of some reason. So now, I want to use tc_malloc in the header file but not replace all malloc. How can I do it?

I know that malloc is a weak symbol so if link the library to my project will replace it. Do you have some method to only use tc_malloc?

1

There are 1 answers

1
Botje On BEST ANSWER

All the overrides are in the libc_override.h file, which is compiled by default. However, there is a second target which does not include this file.

bazel build //tcmalloc:tcmalloc_internal_methods_only should get you a TCMalloc library without the override.