About the Storage allocation

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

1.Static & Dynamicpost

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/functionflex

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

dynamic: storage can be allocated when program is ruuning.this

2.Heapspa

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.orm

advantage:dynamic storage managementhtm

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

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