When I use LD_PRELOAD=/usr/local/lib/libtcmalloc.so
, all my calls to malloc become tcmalloc calls. However, when I link statically against libtcmalloc, I find that straight malloc is getting called unless I still use the LD_PRELOAD
setting.
So how can I statically compile against tcmalloc in such a way that my mallocs hook into tcmalloc?
Notes:
- I'm using lots of C++ new etc, so just #defining malloc to tcmalloc won't work
- Possibly I have to use malloc_hook myself, but I would have thought I could get tcmalloc to do it for me, since it clearly is doing it when linking dynamically