开发者

Which is G++ 4.4.1 default allocator?

开发者 https://www.devze.com 2022-12-28 17:36 出处:网络
I was wondering which is the default memory allocator in G++ 4.4.1, on Ubuntu 9.1. I am interested in comparing different C++ allocator开发者_StackOverflow中文版s in a multithreaded environment. And w

I was wondering which is the default memory allocator in G++ 4.4.1, on Ubuntu 9.1. I am interested in comparing different C++ allocator开发者_StackOverflow中文版s in a multithreaded environment. And where can I get more information about the default memory allocator?

EDIT: I refer to new and delete operators. The only linking is to rt and pthread

Regards


You can use the LD_PRELOAD variable to use your own allocator.
LD_PRELOAD="/path/your_lib_exporting_malloc.so"

Running any application dynamically linked with glibc in the same terminal will actually use the malloc implementation you provided.
Many malloc implementation are freely available.
* TLSF
* jemalloc
* dlmalloc (Doug Lea’s malloc, been around forever)
* ptmalloc2 (Doug Lea’s malloc, extended to support per-thread arenas.)
* TCMalloc (Google’s malloc, claims to be 6x faster than ptmalloc2)
* nedmalloc (claims to be faster than tcmalloc)
* Hoard, also claims to be very fast
(source: Josh Haberman's blog)


G++ will create references to operator new() in libstdc++ that comes with G++. That in turn uses the malloc() defined in the libc that is installed on your system (usually glibc).

Most replacement allocators will point one of them to their implementation, usually they just replace malloc(). For example, you can use Google's TC Malloc by simply preloading their shared library. No changes to the compiled application necessary.


The g++ new operator is indeed implemented using glibc malloc.
Memory allocation itself is then performed using the standard unix system call mmap.

You can get more information about your memory allocator using mallinfo.
See Statistics-of-Malloc and Efficiency-and-Malloc for more information.

0

精彩评论

暂无评论...
验证码 换一张
取 消