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

36,918

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.

Share:
36,918
Mickey Shine
Author by

Mickey Shine

Updated on January 13, 2022

Comments

  • Mickey Shine
    Mickey Shine over 2 years

    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 them in my application?