What are the differences among static, dynamic, and automatic allocation?
相关问题
- how to define constructor for Python's new Nam
- Keeping track of variable instances
- What uses more memory in c++? An 2 ints or 2 funct
- Object.create() bug?
- Achieving the equivalent of a variable-length (loc
相关文章
- 接口B继承接口A,但是又不添加新的方法。这样有什么意义吗?
- Angular Material Stepper causes mat-formfield to v
- Private static variables in php class
- NameError: name 'self' is not defined, eve
- Passing static array in attribute
- Implementation Strategies for Object Orientation
- Java “static import” vs. “import static” in Java 8
- Check if the Type of an Object is inherited from a
Static allocation is memory that has been set aside for an application when it is first loaded. This section of memory is kept to be only used with that application, and is made available again once the program is closed.
Dynamic allocation is memory that is allocated as needed, and deallocated/released when it is no longer needed. Heaps and stacks are examples of areas of memory that can be dynamically allocated.
There will be language-specific details, but the general idea is:
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).