What is the best solution to replace a new memory allocator in an existing code?
From the TCMalloc documentation:
To use TCmalloc, just link tcmalloc into your application via the "-ltcmalloc" linker flag. You can use tcmalloc in applications you didn't compile yourself, by using LD_PRELOAD:
$ LD_PRELOAD="/usr/lib/libtcmalloc.so"
ptmalloc seems to be similar (but if you're on Linux, you're likely already using it because it's part of the GNU C library).
I would expect operator new
to call malloc
, but you can easily check for yourself by setting a breakpoint on malloc
, then calling new
. If your new
doesn't call malloc
, you can redefine it so that it does.