C#有没有对象的数组存储的指针表示对象? [英] C# Does an array of objects store the pointers of said objects?

查看:339
本文介绍了C#有没有对象的数组存储的指针表示对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有绝对有是这样的一个问题,但我无法找到它 - 也许我措辞是错误的。我的所有搜索都导致文章如何在C#中使用数组。

There definitely has to be a question like this, but I'm unable to find it - perhaps I'm phrasing it wrong. All my searches have led to articles on how to use arrays in C#.

一个小背景:我想许多对象加载到一个数组。我不知道是否该阵列将得到OutOfMemory例外,由于太多的指针或数组中的累计对象的大小。我知道,对象在.NET与生俱来的2 GB的大小限制,但它与对象本身数组中的干?

A little background: I'm trying to load many objects into an array. I'm wondering if the array will get the OutOfMemory exception due to too many pointers or the size of the cumulative objects in the array. I know that objects have an innate 2 GB size limit in .NET, but does it stem from the objects themselves in the array?

例如,如果我有N个数组中的对象,并在数组有N * sizeof的(对象)或n * sizeof的(指针)?

For example, if I have n objects in the array, does the array have a memory size of n * sizeof(object) or n * sizeof(pointer)?

推荐答案

如果对象是值类型,则它的存储阵列中的实际物体和所述阵列的大小是n *的对象的大小。如果类型是引用类型则该数组存储在别处的对象的引用,并且阵列的大小是n *的大小指示器的

If the objects are value types, then it's storing the actual objects in the array and the size of the array is n * the size of the object. If the types are reference types then the array is storing references to the objects elsewhere, and the size of the array is n * the size of a pointer.

这篇关于C#有没有对象的数组存储的指针表示对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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