zoukankan      html  css  js  c++  java
  • 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:文中若出现语法错误,请见谅并指出,大家可互相学习

  • 相关阅读:
    2020年12月2日
    2020年12月1日
    2020年11月30日
    2020年11月29日
    2020年11月28日
    2020年11月27日
    2020年11月26日
    2020年11月25日
    浅谈扩展欧几里得算法
    Hello 2020
  • 原文地址:https://www.cnblogs.com/allenpengyu/p/3422851.html
Copyright © 2011-2022 走看看