静态分配与动态分配与自动分配 [英] Static allocation vs. Dynamic allocation vs. Automatic allocation

查看:262
本文介绍了静态分配与动态分配与自动分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

静态,动态和自动分配有什么区别?

解决方案

将有语言特定的细节,但是一般的想法是:



  • 静态:在程序启动时分配,存在于程序的整个生命周期

  • 自动:分配$ block
    $ b

    动态分配需要更多解释:分配时分配(分配)例如,像新的XXX这样的东西)。在(C ++的大多数实现)中,直到你明确删除它才会存在。使用大多数较新的语言(例如Java,C#),它将存在,直到垃圾收集器确定它不再可访问,此时将自动销毁。



    并非所有语言都有三种分配形式。在某些情况下(例如Java),即使支持一种分配形式,也有限制,例如允许自动分配内置类型,但需要动态分配对象类型(即类的实例)。


    What are the differences among static, dynamic, and automatic allocation?

    解决方案

    There will be language-specific details, but the general idea is:

    • Static: allocated at program startup, exists for entire life of program
    • Automatic: allocated upon entry into a block, exists for duration of that block

    Dynamic allocation requires a bit more explanation: it's allocated when you allocate it (e.g. with something like 'new XXX'). In (most implementations of) C++, it'll exist until you explicitly delete it. With most newer languages (e.g. Java, C#) it'll exist until the garbage collector determines that it's no longer accessible, at which time it'll be destroyed automatically.

    Not all languages have all three forms of allocation. In some cases (e.g. Java), even if a form of allocation is supported, there are restrictions such as allowing automatic allocation for built-in types, but requiring dynamic allocation for object types (i.e. instances of classes).

    这篇关于静态分配与动态分配与自动分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆