I am clear about Window heap allocation and stack of heaps etc. Though being new to Linux, i do not have much clarity how does it work?
On Windows:
- At the beginning of a process, the OS creates a default heap called Process heap. The Process heap is used for allocating blocks if no other heap is used.
- Language run times also can create separate heaps within a process. (For example, C run time creates a heap of its own.)
- Besides these dedicated heaps, the application program or one of the many loaded dynamic-link libraries (DLLs) may create and use separate heaps, called private heaps
- These heap sits on top of the operating system's Virtual Memory Manager in all virtual memory systems.
- a) C/C++ Run-time (CRT) allocator: Provides malloc() and free() as well as new and delete operators. b) The CRT creates such an extra heap for all its allocations (the handle of this CRT heap is stored internally in the CRT library in a global variable called _crtheap) as part of its initialization. c) CRT creates its own private heap, which resides on top of the Windows heap. d) The Windows heap is a thin layer surrounding the Windows run-time allocator(NTDLL). e) Windows run-time allocator interacts with Virtual Memory Allocator, which reserves and commits pages used by the OS.
Our DLLs and exe link to multithreaded static CRT libraries. Each DLL and exe we create has a its own heap, i.e. _crtheap. The allocations and de-allocations has to happen from respective heap. That a dynamically allocated from DLL, cannot be de-allocated from executable and vice-versa.
Compiling our code in DLL and exe’s using /MD or /MDd to use the multithread-specific and DLL-specific version of the run-time library, will link both DLL and exe to the same C run time library and hence one _crtheap. Allocations are always paired with de-allocations within a single module.
Is this the same behavior on Liunx? What all heaps are there? What about CRT heaps?