栈和堆
栈和堆
技术博客http://www.cnblogs.com/ChenYilong/
新浪微博http://weibo.com/luohanchenyilong
栈和堆
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_096c21ac7dab507da62605ba71888946.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_78a7174684b5cd9f70830e307e7b0ae1.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_ba023f8e134ef9de8326ad328c30d5ab.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_d634de27e1d3d40d7412cf044725ef74.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_de87bfa2d65289709c63d9101c95e83b.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_3b5273ec66f43433f8209d79a4e7c493.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_9b9daba60ff84b0e715372531b453380.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_f0b8e9e20838423def953225f871e15a.png)
技术博客http://www.cnblogs.com/ChenYilong/新浪微博http://weibo.com/luohanchenyilong
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_cf3d3e5c2bf803657156801886c5d7dc.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_0b35eafe230b6f34f09569e5ff37bb7f.png)
数据在内存中的存放
.1. 栈区(stack) 由编译器自动分配并释放,一般存放函数的参数值,局 部变量等
.2. 堆区(heap) 由程序员分配和释放,如果程序员不释放,程序结束时, 可能会由操作系统回收
.3. 寄存器区 用来保存栈顶指针和指令指针
.4. 全局区(静态区)全局变量和静态变量的存储是放在一起的,初始 化的全局变量和静态变量存放在一块区域,未初始化的全局变量和 静态变量在相邻的另一块区域,程序结束后由系统释放。
.5. 文字常量区 存放常量字符串,程序结束后由系统释放
.6. 程序代码区 存放函数的二进制代码
栈
栈:
1> 大小有限制 iOS(主线程) 1M
2> 栈的内存是连续的 栈的空间一旦被耗尽,程序直接overflow
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_91bf0d25ef8061e1ca21c8ac64f3352a.png)
栈--程序执行所在的内存空间(压栈,先进后出)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_b3531144e4464eb95a83930189e3c4ba.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_897b223fe1bf63457e55de6d396ff5bb.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_897b223fe1bf63457e55de6d396ff5bb.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_897b223fe1bf63457e55de6d396ff5bb.png)
栈
I =>相当于一个标签,程序中可以通过这个标签来访问到变量的内容
堆
只负责申请空间,不负责贴标签
只是负责申请空间,并返回给指针
进程&线程
• 进程的作用:分配程序的内存空间 •线程是指令集合,顺序执行• 每个进程都包含一个主线程
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_a5df9702170d4f0af1aa52b056c88fdc.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_b3531144e4464eb95a83930189e3c4ba.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_b64e9b278cd2daa395fd8e067dd5ccb3.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_897b223fe1bf63457e55de6d396ff5bb.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_b3531144e4464eb95a83930189e3c4ba.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_25a62e35b36da54334994db6a726ff46.png)
![](http://postachio-images.s3-website-us-east-1.amazonaws.com/96083b7bb56878d8f4821117b754ca3a/809dd19bbb7194193799161f3b8831cb/w600_897b223fe1bf63457e55de6d396ff5bb.png)
© chenyilong. Powered by Postach.io
作者:
出处:http://www.cnblogs.com/ChenYilong/(点击RSS订阅)
本文版权归作者和博客园共有,欢迎转载,
但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。