search

Home  >  Q&A  >  body text

c++ - jemalloc 怎么自动替换掉项目中已使用的malloc和new?

请教一下
在windows下使用jemalloc,看了下测试例子,是调用je_mallocje_free操作的
但是项目中已经有了很多malloc和new

必须自己去处理new以及stl::allocator替换成je_malloc么?
还是有类似tcmalloc一样比较方便的使用方法?

伊谢尔伦伊谢尔伦2802 days ago2445

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-17 15:05:28

    I don’t know how you use it under Windows, and I’m not familiar with VS, but the principle should apply.
    If you still use gcc/mingw, you can directly link the jemalloc library first and then globally replace it with the implementation using jemalloc.
    Here is an example:
    cc ​​app.c -o app -L${JEMALLOC_PATH}/lib -Wl,-rpath,${JEMALLOC_PATH}/lib -ljemalloc
    From the documentation:
    https ://github.com/jemalloc/j...
    In Linux, you can also directly add the compiled jemalloc library path to LD_LIBRARY_PATH

    This is a common use of dependency injection during connection.
    You can try to answer where the original malloc function came from, and how is it connected to the current program?

    reply
    0
  • Cancelreply