如何创建数组访问和 [英] How are arrays created and accessed

查看:126
本文介绍了如何创建数组访问和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我明白(不是完全为什么,虽然)的基本类型,如整型,浮点的实例存储在堆栈上,并不堆分配。但我有点困惑基本类型数组是如何存储和访问。我有这个问题,因为System.Array的是引用类型。而引用类型堆中分配。

I understand(not completely why, though) that instances of primitive types such as int, float are stored on the stack and are not heap allocated. But I am a bit confused about how arrays of primitive types are stored and accessed. I have this question because System.Array is a reference type. And reference types are heap allocated.

int[] integers = {1,2,3,4,5};

如何在这些个体整数存储和内存访问?

How are these individual integers stored and accessed on the memory?

推荐答案

您理解是有缺陷的,基本上是这样。值类型值的有时的存储在堆栈上 - 而不是在一个数组或任何其他基于堆的对象的一部分。这是不幸的,有些人选择让生活栈,然后混淆他人围绕价值类型,例如毯子声明:(

Your "understanding" is flawed, basically. Value type values are sometimes stored on the stack - but not when part of an array or any other heap-based object. It's unfortunate that some people choose to make such a blanket statement around value types living on the stack, which then confuses others :(

此外,的栈/堆的区别是一个实现细节 ...

请参阅我对一些细节的内存文章,但的绝对的阅读埃里克利珀的博客文章(在上一段链接)以获得更多的哲学的注意事项。(阅读他的< A HREF =htt​​p://blogs.msdn.com/b/ericlippert/archive/tags/value+types/相对=nofollow>其他价值类型的职位了解更多的信息。)

See my article on memory for some more details, but definitely read Eric Lippert's blog post (linked in the previous paragraph) for more philosophical considerations. (Read his other posts on value types for even more information.)

这篇关于如何创建数组访问和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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