C++中关于variable 内存分配的问题.

https://github.com/jfl913/Notes/commit/02c7410b9bfca50f33b1999668f2dffeade6203f
    +The Stack
    +> When a method (or function) is executed, a chunk of memory is allocated from a part of memory called the stack. This chunk of memory is called a frame, **and the frame stores the values for variables declared inside the method**. A variable declared inside a method is called a local variable.
    +
    +The Heap
    +
    +> The heap, on the other hand, is where all Objective-C **objects** live. It is a giant heaping mess of **objects**. You use pointers to keep track of where those **objects** are stored in the heap.
    +>
    +> When you send the alloc message to a class, a chunk of memory is allocated from the heap.
    +
    +总结:**Stack里面存放的是`local variable`(局部变量),Heap里面存放的是`objects`(对象)**
    +
    +我也从网上查到了由C/C++编译的程序占用的内存分为的以下几个部分:
    +
    +> 1. 栈区(stack)— 由**编译器**自动分配释放,存放函数的**参数值****局部变量的值**等。其
    + 操作方式类似于数据结构中的栈。
    + 2. 堆区(heap) — 一般由**程序员**分配释放,若程序员不释放,程序结束时可能由OS回
    + 收 。注意它与数据结构中的堆是两回事,分配方式倒是类似于链表,呵呵。
    + 3. 全局区(静态区)(static)—,全局变量和静态变量的存储是放在一块的,初始化的
    + 全局变量和静态变量在一块区域,未初始化的全局变量和未初始化的静态变量在相邻的另
    + 一块区域。 - 程序结束后由系统释放。
    + 4. 文字常量区—常量字符串就是放在这里的。程序结束后由系统释放
    + 5. 程序代码区—存放函数体的二进制代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值