发现我是多么的内存可以分配在C#中的数组 [英] Finding how much memory I can allocate for an array in C#

查看:326
本文介绍了发现我是多么的内存可以分配在C#中的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做一些计算,需要一个大的阵列进行初始化。该阵列的最大大小决定了我能解决这个问题的最大尺寸。

I am doing some calculations that require a large array to be initialized. The maximum size of the array determines the maximum size of the problem I can solve.

有没有一种方法以编程方式确定有多少内存可用于比方说,字节可能吗?

Is there a way to programmatically determine how much memory is available for say, the biggest array of bytes possible?

感谢

推荐答案

那么,依靠一个单一的巨大的阵列上有一系列的相关问题 - 内存碎片,连续的块中,的最大对象大小等限制。如果你需要大量的数据,我会建议创建模拟使用大量的小(但仍然大)阵列的大阵的一类,每一个固定大小的 - 即索引分向找到相应的数组,然后使用%的数组中得到补偿。

Well, relying on a single huge array has a range of associated issues - memory fragmentation, contiguous blocks, the limit on the maximum object size, etc. If you need a lot of data, I would recommend creating a class that simulates a large array using lots of smaller (but still large) arrays, each of fixed size - i.e. the indexer divides to to find the appropriate array, then uses % to get the offset inside that array.

您可能还需要确保你是在一个64位操作系统,拥有大量内存。这会给你最大的可用头部空间。

You might also want to ensure you are on a 64-bit OS, with lots of memory. This will give you the maximum available head-room.

根据不同的情况下,更复杂的算法,如稀疏数组,ETA-载体等可能会利用最大化你可以做什么。你可能会很惊讶人们可以做什么多年前内存有限,只是磁带旋转前后...

Depending on the scenario, more sophisticated algorithms such as sparse arrays, eta-vectors, etc might be of use to maximise what you can do. You might be amazed what people could do years ago with limited memory, and just a tape spinning backwards and forwards...

这篇关于发现我是多么的内存可以分配在C#中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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