创建一个大阵的数字(10 ^ 9尺寸) [英] Creating a large array of numbers (10^9 size)

查看:153
本文介绍了创建一个大阵的数字(10 ^ 9尺寸)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个数组,它是能够存储10 ^ 9号(长整型)。如果我尝试这样做,我的编译器crashes.What是最大大小的数组允许在C ++中。另外,如果我这样做也是动态的我得到同样的problem.How我可以完成我期待acheive任务?
谢谢,任何帮助将是AP preciated。

I want to create an array that is capable of storing 10^9 numbers(long int).If i try doing this my compiler crashes.What is the maximum size array allowed in C++.Also if i do this dynamically too i get the same problem.How can i accomplish the task i am looking to acheive? Thanks, any help would be appreciated.

推荐答案

最大的数组大小取决于你存储数据(和整数提供给它们编制索引)。

The maximum array size is dependent on the data you store (and the integers available to index them).

因此​​,一个32位系统上,你最多只能索引2³²元素,如果你运气好,这是一个有点以上10⁹。在64位系统中,你可以索引2⁶⁴元素,这是有点高于10 19。这本质上是最大的数组大小。能够不意味着你也可以实际获得从操作系统多,作为实际的虚拟地址空间可能是小得多的索引。在Linux上,约一个虚拟ADRESS空间。 64万亿字节的每个进程中可用在64位,这是2⁴²字节。

So on a 32bit system, you can only index 2³² elements at most if you're lucky, which is a bit above 10⁹. On a 64bit system, you can index 2⁶⁴ elements, which is a bit above 10¹⁹. This is essentially the maximum array size. Being able to index that does not imply that you can also actually get that much from the operating system, as the actual virtual address space might be much smaller. On Linux, a virtual adress space of approx. 64 Terabytes is available per process on 64bit, which are 2⁴² bytes.

但是,如果你真的尝试分配这一点,你需要这么多数量的字节!所以,如果你尝试分配长整型这将可能成为大小的64位的数组,你需要8 GB的内存。

However, if you actually try to allocate this, you need that much amount of bytes! So if you try to allocate an array of long int which will probably be 64bits of size, you need 8 Gigabytes of memory.

在32位系统中,这是不可能的。在64位系统中,你需要有RAM和交换空间的量的​​工作。

On a 32bit system, this is impossible. On a 64bit system, you need to have that amount of ram and swap space to work.

如果你在一个32位系统或没有足够的内存在64位系统上,你会得到一个内存不足的错误,这可能是你看到的行为的原因。

If you're on a 32bit system or on a 64bit system without enough memory, you'll get a out of memory error, which is probably the reason for the behaviour you see.

如果您还尝试在你的可执行文件的.data段静态创建数组,可执行可为8 GB的大,你可能会遇到文件系统限制结束(FAT32人?)。此外,编译器可能扼流圈的数据量(在32位,它可能会崩溃)。

If you also try to create the array statically in a .data section of your executable, the executable may end up with being 8 GBytes large, where you could run into filesystem limits (fat32 anyone?). Also the compiler probably chokes on the amount of data (on 32bit, it'll probably crash).

如果你分配在栈上(这是作为一个静态大小的局部变量数组),你也会碰到某些操作系统堆栈限制。

If you're allocating on stack (this is, as a statically sized local variable array), you'll also run into stack limits on certain operating systems.

这篇关于创建一个大阵的数字(10 ^ 9尺寸)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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