您的位置:首页 > Web前端

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: