C++ STL with jemalloc

前端 未结 5 1340
渐次进展
渐次进展 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:08

    If you want to replace malloc everywhere in your program (which I wanted to and also seems the only logical solution), then all you have to do is link against it.

    So, if you use gcc then all you have to do is:

    g++ yourprogram.cpp -ljemalloc
    

    But, if it's not possible, then you have to use jemalloc via another functions e.g. je_malloc and je_free, and then you have to overload the new and delete operators.

    There's no need for including any header if you don't use implementation-specific features (statistics, mostly).

提交回复
热议问题