CareerCup What is the difference between a computers heap and it's stack?
2014-02-22 21:04
531 查看
Physically stack and heap both are allocated on RAM and their implementation varies from language, compiler and run time
Stack is used for local variables of functions and to track function calling sequences. Heap is used for allocating dynamically created variables using malloc, calloc
or new.
Stack memory is freed whenever the function completes execution but the heap memory needs to be freed explicitly using delete, free or by garbage collector of the language.
Stack memory of a process is fixed size and heap is variable memory.
Stack is faster than heap as allocating memory on stack is simpler just moving stack pointer up.
In case of multi threading, each thread of process will have a different stack but all threads share single heap
Stack is used for local variables of functions and to track function calling sequences. Heap is used for allocating dynamically created variables using malloc, calloc
or new.
Stack memory is freed whenever the function completes execution but the heap memory needs to be freed explicitly using delete, free or by garbage collector of the language.
Stack memory of a process is fixed size and heap is variable memory.
Stack is faster than heap as allocating memory on stack is simpler just moving stack pointer up.
In case of multi threading, each thread of process will have a different stack but all threads share single heap
相关文章推荐
- What is the difference between '/n' and '/r/n'? /n /r/n的区别是什么
- What is the difference between a = a * (2^3) and a = a << 3?
- What is the difference between angle bracket < > and double quotes " " while including header files
- What's the difference between a URI and a URL?
- What is the difference between differed processing mode and interactive mode?
- what is the difference between processes and threads
- What is the difference between a URI, a URL and a URN
- What is the difference between a thread and a process?
- What is the difference between SMOD and CMOD?
- What is the Difference Between Type and Class in
- What is the difference between WinRT, UWP and WPF?
- What is the difference between LINQ to SQL and LINQ to Entities?
- What is the difference between extensibility and scalability?
- What is the difference between addView and addViewInLayout?
- What is the basic difference between NSTimer, NSTask, NSThread and NSRunloop?
- What is the difference between Facade and Gateway design patterns?
- Green and native threads -- what's the difference?
- what is the difference between json and javascript object.
- What is the Differences Between Sleep/Standby and Hibernate
- What is the difference between a URI, a URL and a URN