开发者

C# array with capacity over Int.MaxValue

I was wondering if there is any stru开发者_开发技巧cture in C# that can contain more than Int.MaxValue's restriction of 2,147,483,647 items, in case of really large sets of information. Would this have to be done with multi level arrays? Or could you create an array that has a maximum length of Long.MaxValue? If so, how?


It's been done, a sample BigArray<T> implementation is here.


The CLR currently has a limit of 2GB for any single object - so you'd have to build it out of multiple arrays, even for an element type of byte. That should be feasible though. Most of the normal collection interfaces would fail as they use int for the index, count etc.

I believe the CLR itself isn't restricted to an overall process limit which would prevent this - although you'd almost certainly want to be running on a 64-bit CLR and OS, of course.


What is your requirement? It's hard to believe that an array with more elements than this is going to be the correct solution for any real-world problem, irrespective of whether it's legal or not. You may be thinking of a database here, whether persisted or in-memory. That's the standard means for organizing very large datasets.


You could only use an index based structure if the indexer was a long (int64) rather than an int32.

Even a List wouldn't work as the indexer is an int32.


Very little computers will have enough memory to hold such structure in-memory.


ArrayList can contain more than Int.MaxValue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜