What are the differences between (and reasons to choose) tcmalloc/jemalloc and memory pools?

前端 未结 1 1495
醉梦人生
醉梦人生 2021-01-29 20:32

tcmalloc/jemalloc are improved memory allocators, and memory pool is also introduced for better memory allocation. So what are the differences between them and how to choose the

1条回答
  •  抹茶落季
    2021-01-29 21:08

    It depends upon requirement of your program. If your program has more dynamic memory allocations, then you need to choose a memory allocator, from available allocators, which would generate most optimal performance out of your program.

    For good memory management you need to meet the following requirements at minimum:

    1. Check if your system has enough memory to process data.
    2. Are you albe to allocate from the available memory ?
    3. Returning the used memory / deallocated memory to the pool (program or operating system)

    The ability of a good memory manager can be tested on basis of (at the bare minimum) its efficiency in retriving / allocating and returning / dellaocating memory. (There are many more conditions like cache locality, managing overhead, VM environments, small or large environments, threaded environment etc..)

    With respect to tcmalloc and jemalloc there are many people who have done comparisions. With reference to one of the comparisions:

    http://ithare.com/testing-memory-allocators-ptmalloc2-tcmalloc-hoard-jemalloc-while-trying-to-simulate-real-world-loads/

    tcmalloc scores over all other in terms of CPU cycles per allocation if the number of threads are less. jemalloc is very close to tcmalloc but better than ptmalloc (std glibc implementation).

    In terms of memory overhead jemalloc is the best, seconded by ptmalloc, followed by tcmalloc.

    Overall it can be said that jemalloc scores over others. You can also read more about jemalloc here:

    https://www.facebook.com/notes/facebook-engineering/scalable-memory-allocation-using-jemalloc/480222803919

    I have just quoted from tests done and published by other people and have not tested it myself. I hope this could be a good starting point for you and use it to test and select the most optimal for your application.

    0 讨论(0)
提交回复
热议问题