Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is G++ 4.4.1 default allocator?

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++ allocators 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

like image 785
Cowboy Avatar asked May 02 '10 21:05

Cowboy


2 Answers

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.

like image 90
log0 Avatar answered Nov 15 '22 10:11

log0


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.

like image 1
Gene Vincent Avatar answered Nov 15 '22 12:11

Gene Vincent