C++ STL with jemalloc

前端 未结 5 1342
渐次进展
渐次进展 2021-02-05 13:56

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

5条回答
  •  旧巷少年郎
    2021-02-05 14:18

    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

提交回复
热议问题