Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual-C++ malloc implementation?

I'm currently studying the malloc implementation for my homework.

I know there exists some versions of malloc implementation like ptmalloc, used by glibc, and jemalloc, used by FreeBSD.

I wonder which version of implementation is adopted by visual C++? Or the VC++ team just implemented their own version?

like image 726
lei_z Avatar asked May 12 '12 13:05

lei_z


1 Answers

When you call malloc or new in a VC++ compiled program without writing your own redirector you end up in HeapAlloc, that is also known as NT Heap.

NT Heap is developed by the Windows memory team. These guys are responsible for all memory management in the OS. They allocate virtual space for user-mode processes; they handle memory for drivers, etc. It is logical that the same team provides code for small allocations in the application code. From my experience, NT heap is a good thing. It does not have any major flaws. When you have very specific requirements, some other allocator may perform better. In the general case, NT heap is the right starting point. Most likely it will satisfy your needs.

Note that VC++ is a compiler. It creates an executable that runs under control of the operating system. It is not correct to speak about any "VC++ executing environment".

Nevertheless, I know that the compiler itself is not using NT heap when it compiles the code. They use their own allocator. I do not know the exact reasons why they did that.

like image 175
Kirill Kobelev Avatar answered Oct 09 '22 11:10

Kirill Kobelev