是一个数组的大小为int(2147483647)的上限的限制? [英] Is the size of an array constrained by the upper limit of int (2147483647)?

查看:3988
本文介绍了是一个数组的大小为int(2147483647)的上限的限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一些项目欧拉练习,我碰到,我<击>有无<情景/行使>想这比2,147,483,647( INT 的C#中的上限)更大的阵列。

I'm doing some Project Euler exercises and I've run into a scenario where I have want arrays which are larger than 2,147,483,647 (the upper limit of int in C#).

当然这些都是大型数组,但为例,我不能这样做。

Sure these are large arrays, but for instance, I can't do this

// fails
bool[] BigArray = new BigArray[2147483648];

// also fails, cannot convert uint to int
ArrayList BigArrayList = new ArrayList(2147483648);

所以,我可以有更大的阵列?

So, can I have bigger arrays?

编辑:
这是一个筛,你知道的,所以我只是想真的大单:D

It was for a Sieve of Atkin, you know, so I just wanted a really big one :D

推荐答案

您与数组这个大的工作任何时候,你应该设法找到一个更好的解决问题的办法。但尽管如此我还是会尝试回答你的问题。

Anytime you are working with an array this big, you should probably try to find a better solution to the problem. But that being said I'll still attempt to answer your question.

在本的文章中提到有2 GB的限制在.ne​​t中的任何对象。对于所有x86,x64和IA64。

As mentioned in this article there is a 2 GB limit on any object in .Net. For all x86, x64 and IA64.

与32位Windows操作系统
  系统上有一个2GB的限制
  一个对象,你可以创建而大小
  运行64位应用程序管理
  在64位Windows操作系统。

As with 32-bit Windows operating systems, there is a 2GB limit on the size of an object you can create while running a 64-bit managed application on a 64-bit Windows operating system.

此外,如果你定义一个数组在栈上过大,你将有一个堆栈溢出。如果定义堆上的阵列,它会尝试分配这一切在一个大的连续的块。这将是更好地使用具有堆隐含动态分配一个ArrayList。这不会让你得到过去2GB,但可能让你得到更接近它。

Also if you define an array too big on the stack, you will have a stack overflow. If you define the array on the heap, it will try to allocate it all in one big continuous block. It would be better to use an ArrayList which has implicit dynamic allocation on the heap. This will not allow you to get past the 2GB, but will probably allow you to get closer to it.

我认为堆栈大小限制将会越来越仅当您使用的是64位或IA64体系结构和操作系统。使用的x64或IA64您将有64位分配的内存而不是32位。

I think the stack size limit will be bigger only if you are using an x64 or IA64 architecture and operating system. Using x64 or IA64 you will have 64-bit allocatable memory instead of 32-bit.

如果您无法一次性全部分配数组列表,你也许可以分配它的部分。

If you are not able to allocate the array list all at once, you can probably allocate it in parts.

使用一个数组列表,并以64位Windows 2008的计算机上的时间与6GB的内存加1对象,最让我可以得到的ArrayList的就是尺寸:134217728.所以我真的觉得你必须找到一个更好的解决方案您的问题,不使用尽可能多的内存。或许写入文件,而不是使用RAM。

Using an array list and adding 1 object at a time on an x64 Windows 2008 machine with 6GB of RAM, the most I can get the ArrayList to is size: 134217728. So I really think you have to find a better solution to your problem that does not use as much memory. Perhaps writing to a file instead of using RAM.

这篇关于是一个数组的大小为int(2147483647)的上限的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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