临时对象存储在哪里? [英] Where are temporary object stored?

查看:161
本文介绍了临时对象存储在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IMO临时对象存储在动态(堆)内存中,但我不确定。

IMO temporary objects are stored in dynamic (heap) memory, but I'm not sure. Can you please confirm or deny my thoughts?

推荐答案

标准不会为它们指定任何内存区域(堆/堆栈)但它们就像局部变量自动存储,即在表达式的末尾(或者当绑定到一个ref-to-const时更长),它们被销毁。

The standard does not mandate any memory area (heap/stack) for them, but they are just like local variables "automatic storage", that is at the end of the expression (or longer when bound to a ref-to-const) they are destructed.

大多数实现会像局部变量一样将它们存储在堆栈中。

Most implementations will store them on the stack just like local variables.

strong>

正如James Kanze指出的:在临时的生命周期通过ref-to-const扩展的情况下,它的存储位置在大多数实现上有些确定由该引用的存储位置。也就是说,在引用存在于静态存储器中的情况下,临时数据库也将过期(仅在gcc上确认)。 (虽然IMHO虽然这仍然是暂时的标准意义上,这是可以争论的是这是一个暂时的直觉的英语意义上的那个词)

As James Kanze pointed out: In the case the lifetime of a temporary is extended via a ref-to-const, its store location is on most implementations somewhat determined by the storage location of that reference. That is, in the case of the reference being in static storage, the temporary will be too (just confirmed on gcc). (although IMHO while this is still a temporary in the standards sense, it is arguable whether this is a temporary in the intuitive english sense of that word)

这篇关于临时对象存储在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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