In windows operating system, the stack memory is a thread-specific storage, and the call stack is the logic flow of a series of methods. So each thread has it's own stack area. I want to know how heap memroy area is used? Is it thread-specific? Process-specific? Or in .NET, AppDomian-specific? Or shared between all the user applications and the operating system? Many thanks.
Heap is the most common way to implement dymanic memory allocation. The typical use scenario of using a heap includes when you do not know how much memory to allocate until runtime, or the desired memory is too large to be allocated in the stack.
A process can hold one or more heaps. Most processes have more than on heaps. For example in Windows a process can have default process heap, CRT heap, and the application can call Windows API to create its own heap (using API HeapCreate).
When a process is created the OS will create a new heap for it called Default Process Heap, which is actually rarely used in most cases. When we call new/delete and malloc/free we are actually using the CRT heap.
Windows uses some sophisticate datastructure and algorithm to ensure memory allocatioon/deallocation and mangement in heap is effective. However the common fact is that allocating memory in heap can be much slower than in stack.
For more detailed information you can read Jeffrey Richter's great book Windows via C/C++. And you can read Here for some quick understanding of how heap is managed internally in Windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With