ls0f / my-issues

0 stars 0 forks source link

堆内存和栈内存的区别? #5

Open ls0f opened 8 years ago

ls0f commented 8 years ago

栈内存一般是静态内存分配,在编译时间就确定了内存长度,比如声明变量并初始化,还有栈内存会用来暂存函数返回、参数传递等,函数递归调用就会使用栈内存。

堆内存一般用于动态内存分配,比如C语言中的malloc,Java中的new,要自动手动free内存。栈内存由系统自动释放。

Linux 程序内存空间布局

一个典型的Linux C程序内存空间由如下几部分组成:

https://www.ibm.com/developerworks/cn/linux/l-cn-valgrind/

http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap