超大阵

Extra large array

我必须使用大小为 34000x34000 项的二维数组进行数学计算。

明显的问题 - CLR 不可能将如此大的数据部分存储在内存中。我尝试使用 MemoryMappedFile,但在我尝试为对象创建查看器时它也失败了:MemoryMappedFile.CreateViewAccessor()。有没有其他已经存在的方法来存储大型数组? ('cause I havent' 花很多时间尝试实现自定义大数据存储)

谢谢

<gcAllowVeryLargeObjects> 配置元素允许 64 位进程使用超过 2 Gb 的阵列。你可以试试看。

另外,看看sparse arrays能不能帮到你:

A sparse array is an array in which most of the elements have the default value (usually 0 or null). The occurrence of zero-value elements in a large array is inefficient for both computation and storage.

如果您使用的是 .NET 4.5,则可以使用 <gcAllowVeryLargeObjects enabled="true|false"/>-config 元素。它配置 GC 以允许内存中大于 2GB 的对象。参见 this, section "My app works on large datasets (uses objects > 2GB)", respectively this

作为 gcAllowVeryLargeObjects 的替代方案,考虑使用交错数组 - 处理一大块内存(我猜双打大约 10GB)肯定需要一些额外的努力。

YourType[][] array = Enumerable.Range(0, 34000).Select(_ => new YourType[34000]).ToArray();

请注意,您肯定需要 x64 进程才能使用此类数组 - 确保仅使用 x64 显式构建您的 exe。