为什么术语“自动”和“动态”优选超过术语“堆叠”和“堆”在C ++内存管理? [英] Why are the terms "automatic" and "dynamic" preferred over the terms "stack" and "heap" in C++ memory management?

查看:194
本文介绍了为什么术语“自动”和“动态”优选超过术语“堆叠”和“堆”在C ++内存管理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与许多关于SO的问题和答案相关,我已经知道,最好将其生命周期管理的对象称为驻留在自动存储而不是堆栈中。



此外,动态分配的对象不应该被称为驻留在堆上,而是在动态存储中。



我得到有自动,动态和静态存储,但从来没有真正理解自动堆栈和动态堆之间的区别。为什么前者是首选?



我不是在问什么堆栈/堆意味着或内存管理如何工作。我要问为什么自动/动态存储术语比堆栈/堆优先。

解决方案

strong>自动告诉我关于对象的生命周期的信息:具体地说,它自动绑定到封闭范围,并且当该范围自动被 退出。



动态告诉我,对象的生命周期不是由编译器自动控制的,而是

是一个容器类型的重载名称,对于普通的

code> call 和 ret 指令。它不告诉我有关对象的生命周期,除非通过历史协会对象生命周期在C,由于流行的堆栈框架约定。
还要注意,在一些实现中,线程本地存储是在线程的 ,但不限于任何单个函数的范围。



又是一个重载的名称,表示已排序容器的类型或自由商店管理系统。这不是所有系统上唯一可用的免费商店,也不会告诉我有关分配有 new 的对象的生命周期的具体情况。


Related to a lot of questions and answers on SO, I've learned that it's better to refer to objects whose lifetime is managed as residing in automatic storage rather than the stack.

Also, dynamically allocated objects shouldn't be referred to as residing on the heap, but in dynamic storage.

I get that there is automatic, dynamic and static storage, but never really understood the difference between automatic-stack and dynamic-heap. Why are the former preferred?

I'm not asking what stack/heap mean or how memory management works. I'm asking why the terms automatic/dynamic storage are preferred over the terms stack/heap.

解决方案

Automatic tells me something about the lifetime of an object: specifically that it is bound automatically to the enclosing scope, and will be destroyed automatically when that scope exits.

Dynamic tells me that the lifetime of an object is not controlled automatically by the compiler, but is under my direct control.

Stack is an overloaded name for a type of container, and for the related popular instruction pointer protocol supported by common call and ret instructions. It doesn't tell me anything about the lifetime of an object, except through a historical association to object lifetimes in C, due to popular stack frame conventions. Note also that in some implementations, thread-local storage is on the stack of a thread, but is not limited to the scope of any single function.

Heap is again an overloaded name, indicating either a type of sorted container or a free-store management system. This is not the only free store available on all systems, and nor does it tell me anything concrete about the lifetime of an object allocated with new.

这篇关于为什么术语“自动”和“动态”优选超过术语“堆叠”和“堆”在C ++内存管理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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