CareerCup What is the difference between a computers heap and it's stack?

本文详细解释了计算机内存中栈和堆的区别。栈用于存储局部变量和跟踪函数调用顺序,而堆则用于分配动态创建的变量。栈内存随着函数执行结束自动释放,堆内存则需显式释放。此外,栈内存大小固定,而堆内存大小可变。
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值