即使在 .net 中数组中没有值,数组也会占用空间吗?
我在 VB.net 中有一个使用 3D 数组的程序:
Private gridList(10, 900, 900) As GridElement
现在,我只是在上面使用了内存分析器(因为我的应用程序存在一些重大泄漏问题或其他问题),显然,这个数组(在测试时包含 0一次 -30 个元素)正在使用我的应用程序当前使用的内存的 94%。即使它是空的,也会占用大量内存。
我唯一的假设是,即使是空数组也会占用空间!这对我的计划造成了重大打击!
我的问题:
是否有任何替代方案可以让我仍然具有相同的映射能力 ig 我一直这样使用它:
Dim cGE as GridElement = gridList(3, 5, 7)
但是不会为不使用内存的东西占用那么多内存吗?
谢谢!
I have a program in VB.net that uses a 3D array:
Private gridList(10, 900, 900) As GridElement
Now, I just used a Memory Profiler on it (because my application is having some major leak issues or something) and apparently, this array (containing at the moment of testing 0-30 elements at one time) is using 94% of the memory currently in use by my application. Even when it is empty it takes up huge amounts of memory.
My only assumption is that even empty arrays take up space! This puts a major blow into my plans!
My Question:
Is there any alternative to this that allows me to still have the same abilities to map
i.g. I've been using it like this:
Dim cGE as GridElement = gridList(3, 5, 7)
but doesn't hog up so much memory for things that aren't using memory?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不。但是您的数组中有值。因此占用空间。
为了避免在仅访问所有可能元素中的少数元素时在内存中保留大量元素,您需要使用所谓的 稀疏数组。在 .NET 中,最简单的方法是通过
Dictionary
实现,其中您的情况中的键将是三元素结构*,值将是GridElement
。* 如果您使用的是最新版本的 .NET,则可以通过
元组(整数、整数、整数)
No. But your array has values in it. And hence takes up space.
To avoid keeping a lot of elements in memory when you only access a few of all the possible elements, you need to use a so-called sparse array. In .NET, this is easiest implemented via a
Dictionary
, where the key in your case would be a three-element structure*, and the value would be aGridElement
.* If you’re using an up-to-date version of .NET, then you can model this via a
Tuple(Of Integer, Integer, Integer)