对象中的值类型也存储在堆中? [英] Value types in object stored in heap as well?

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

问题描述

我可以想象这个问题已经被问了数千次,但我没有太多运气找到答案,而且这更多是出于好奇而不是需要.

I can imagine this question has been asked thousands of times, but I didn't have much luck in finding the answer, plus this is more out of curiosity than need.

深入研究 C# 的具体细节,我想知道既然对象存储在堆中,那么对象中的值类型是否也存储在堆中还是放在堆栈中?

Digging into the nuts and bolts of C#, I was wondering since objects are stored in the heap, are the value types within the objects stored in the heap as well or are they placed in the stack?

推荐答案

它们存储在堆中,在为引用类型分配的内存中.此外,值类型通常存储在the堆栈".但是,CLI 规范没有指定存储值类型的内存池所在的位置 - 这是一个无关紧要的实现细节.

They are stored in the heap, inside of the memory allocated for the reference type. In addition, value types are often stored in places other than "the stack". However, the CLI spec does not specify where the memory pool that stores value types resides - it's an implementation detail that should not matter.

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

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