How is it possible to use C++ STL containers with jemalloc (or any other malloc
implementation)?
Is it as simple as include jemalloc/jemalloc.h
C++ allows you to replace operator new
. If this replacement operator new
calls je_malloc
, then std::allocator
will indirectly call je_malloc
, and in turn all standard containers will.
This is by far the simplest approach. Writing a custom allocator requires writing an entire class. Replacing malloc
may not be sufficient (there's no guarantee that the non-replaced operator new
calls malloc
), and it has the risks noted earlier by Adrian McCarthy