About the Storage allocation

     It doesn't matter what programming language u use,it's all about the usage of variable---storage management.

1.Static & Dynamic

static: Global constants and the other information/data generated by compiler are allocated static storage. Static storage is built before any execution,and they would stay in memory throughout execution.

Advantage: use for public /global generally; instance object with the same class share static data/function

Disadvantage:can't be changed(lack of flexibility);static function can't manipulate non-static variables

dynamic: storage can be allocated when program is ruuning.

2.Heap

Within programming, if u need to get any storage,u can "new"/"malloc",but at the end of program,u have better "delete"/"free" these storage,only in this way could the program be secure(e.g. no memory leak). From above,we would know that the size of heap can't be detemined by one time generally.

advantage:dynamic storage management

disvadvantage:unsecure(forget to "delete /free"),ineffiency

3.Stack

Any information about local variables,parameters,state,etc. are allocated space on a stack,the same to heap ,its size can't be determined by compile time

advantage: support the recursion

disadvantage: inffiency(indirect addressing)

PS:文中若出现语法错误,请见谅并指出,大家可互相学习

 

转载于:https://www.cnblogs.com/allenpengyu/p/3422851.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值