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:文中若出现语法错误,请见谅并指出,大家可互相学习

  • 相关阅读:
    四十四 常用内建模块 struct
    四十三 常用内建模块 base64
    Django Haystack 全文检索与关键词高亮
    python实现简单tftp(基于udp)
    多线程socket UDP收发数据
    Python 线程复习
    python 进程复习
    python pdb 调试
    Linux 复习
    Django 博客
  • 原文地址:https://www.cnblogs.com/allenpengyu/p/3422851.html
Copyright © 2011-2022 走看看