So when you call malloc or new [] from your C/C++ application, how does the CRT translate it into Windows API calls?
2
It depends if you are in debug or release mode. In release mode, as Pedro said there is HeapAlloc/HeapFree which are kernel functions,
while in debug mode (with visual studio) there is a hand written version of free and malloc (to which new/delete are re-directed) with thread locks and more exceptions detection, so that you can detect more easily when you did some mistakes with you heap pointers when running your code in debug mode. This is one more reason why a code compiled in debug mode is slower.
I think it is the only one API which is “simulated” like this in debug mode.
Just step it into the debugger to understand how it works, if I remember well this debug version uses somes trees of double linked lists.
And this is also with this kind of re-writing of malloc/free that memory consumption analysers work : there is tool for that in visual studio which just uses another .dll as the implementation of allocations functions which notice another data analyser program each time they are called.
Windows has a HeapAlloc function in the win32 API, maybe it’s used.
The major point is that this is not so much related to Windows as it is to your C or C++ implementation. They implement malloc and how new works. So you should go about finding out how malloc and new are implemented in, for example, Visual C++.
I am not a C++ expert, but iirc, you can overload new; so there may be more going on there.