我需要在C#中非常大的数组的长度(大小) [英] I need very big array length(size) in C#

查看:1961
本文介绍了我需要在C#中非常大的数组的长度(大小)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public double[] result = new double[ ??? ];

我存储结果和结果的总数比2,147,483,647这是最大的int32更大。

I am storing results and total number of the results are bigger than the 2,147,483,647 which is max int32.

我试过的BigInteger,ULONG等,但所有的人给我的错误。

I tried biginteger, ulong etc. but all of them gave me errors.

我如何延长数组的大小,可以存储在它里面> 50147483647结果(双)?

How can I extend the size of the array that can store > 50,147,483,647 results (double) inside it?

谢谢...

推荐答案

的2,147,483,648 阵列双旨意占用16GB内存。对于一些人来说,这不是什么大不了的事。我有不会甚至懒得打页面文件,如果我分配了一些这些阵列的服务器。但这并不意味着它是一个好主意。

An array of 2,147,483,648 doubles will occupy 16GB of memory. For some people, that's not a big deal. I've got servers that won't even bother to hit the page file if I allocate a few of those arrays. Doesn't mean it's a good idea.

当你正在处理大量数据的一样,你应该寻找以减少进程的内存影响。有几种方法去这个问题,取决于你如何与数据的工作。

When you are dealing with huge amounts of data like that you should be looking to minimize the memory impact of the process. There are several ways to go with this, depending on how you're working with the data.

如果您的阵列人烟稀少 - 大量的默认/空值与实际有效/有用的数据的一小部分 - 那么稀疏数组可以大大减少对内存的需求。你可以写各种实现优化不同分布状况:随机分布,分组值,任意连续团体等

If your array is sparsely populated - lots of default/empty values with a small percentage of actually valid/useful data - then a sparse array can drastically reduce the memory requirements. You can write various implementations to optimize for different distribution profiles: random distribution, grouped values, arbitrary contiguous groups, etc.

正常工作对任何类型的包含的数据,包括复杂的类。有一定的管理费用,所以实际上可以比赤裸裸的阵列更糟糕,当填充百分比很高。当然,你仍然将使用内存来存储实际数据。

Works fine for any type of contained data, including complex classes. Has some overheads, so can actually be worse than naked arrays when the fill percentage is high. And of course you're still going to be using memory to store your actual data.

在磁盘上存储数据,创建一个读/写的FileStream 的文件,并附在一个包装,可以让你访问该文件的内容,就好像它是一个在存储器阵列。用于顺序从文件中读取的这个最简单的实现给你合理有用性。随机读取和写入可以减缓你失望,但你可以做一些缓冲的背景下,以帮助减轻的速度问题。

Store the data on disk, create a read/write FileStream for the file, and enclose that in a wrapper that lets you access the file's contents as if it were an in-memory array. The simplest implementation of this will give you reasonable usefulness for sequential reads from the file. Random reads and writes can slow you down, but you can do some buffering in the background to help mitigate the speed issues.

此方法适用于具有静态尺寸,包括可以被复制到/从一系列文件中的字节的结构的任何类型。对于像字符串动态大小的数据不起作用。

This approach works for any type that has a static size, including structures that can be copied to/from a range of bytes in the file. Doesn't work for dynamically-sized data like strings.

如果你需要处理动态尺寸记录,稀疏数据,等等,那么你也许可以设计出能够很好地处理它的文件格式。话又说回来,一个数据库可能是在这一点上更好的选择。

If you need to handle dynamic-size records, sparse data, etc. then you might be able to design a file format that can handle it elegantly. Then again, a database is probably a better option at this point.

相同的其他文件的选项,但使用不同的机制来访问数据。见<一href=\"http://msdn.microsoft.com/en-us/library/system.io.memorymappedfiles.memorymappedfile.aspx\"><$c$c>System.IO.MemoryMappedFile对于如何从.​​NET中使用内存映射文件的详细信息。

Same as the other file options, but using a different mechanism to access the data. See System.IO.MemoryMappedFile for more information on how to use Memory Mapped Files from .NET.

根据数据的性质,将其存储在数据库中可能为你工作。对于一个大阵双击 s这个是不太可能但一个很好的选择。读/写数据的数据库中的开销,加上存储开销 - 每一行会至少的需要有一个较大的记录的行的身份,可能是一个BIG_INT(8字节整数),倍增马上蝙蝠的数据的大小。添加的开销为索引,行存储等,并且可以很容易增加你的数据的大小。

Depending on the nature of the data, storing it in a database might work for you. For a large array of doubles this is unlikely to be a great option however. The overheads of reading/writing data in the database, plus the storage overheads - each row will at least need to have a row identity, probably a BIG_INT (8-byte integer) for a large recordset, doubling the size of the data right off the bat. Add in the overheads for indexing, row storage, etc. and you can very easily multiply the size of your data.

数据库是伟大的存储和处理复杂的数据。这就是他们的东西。如果你有可变宽度的数据 - 串之类的 - 那么数据库可能是您的最佳选择之一。在另一面是,他们通常不是那些有大量非常简单的数据工作的最佳解决方案。

Databases are great for storing and manipulating complicated data. That's what they're for. If you have variable-width data - strings and the like - then a database is probably one of your best options. The flip-side is that they're generally not an optimal solution for working with large amounts of very simple data.

哪个选项你去,你可以创建一个的IList&LT; T&GT;封装了你的数据兼容类。这使您可以用code,它没有任何需要了解的如何的存储数据,只有它的

Whichever option you go with, you can create an IList<T>-compatible class that encapsulates your data. This lets you write code that doesn't have any need to know how the data is stored, only what it is.

这篇关于我需要在C#中非常大的数组的长度(大小)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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