使用大整数数组 [英] Working with large integer arrays
问题描述
如何使用大整数,我需要GMP库吗?
我想要一个从0到2 ^ 32的元素数组
如何获取这个工作:
How to work with large integer, do I need GMP libraries or something?
I want an array that has elements starting from 0 to 2^32
How to get this to work:
#include <stdio.h>
int main(){
unsigned int i,j=0,sz=4294967295;
unsigned int A[sz];
A[j]=0;
for(i=1;i<=sz;i++){
A[i]=A[j]+1 ;
j++;
printf("%u\n",A[i]);
}
return 0;
}
错误:进程退出并返回值3221225725
是它是数组太大还是什么?
error: process exited with return value 3221225725
is it that the array is too big or something??
推荐答案
根据谷歌的说法,你的 A
数组是大约17千兆字节。好多啊。你可能已经溢出了堆栈。
According to Google, your A
array is approximately 17 gigabytes. That's a lot. You're probably overflowing the stack.
如果你真的需要这么多内存,你可以 malloc()
相反,但在较旧的 32位架构上,你基本上没有运气(地址空间的硬上限为4 GB,减去内核空间。
If you really need this much memory, you may be able to malloc()
it instead, but on older 32-bit architectures, you're basically out of luck (address space has a hard upper limit of 4 GB, minus kernel space).
这篇关于使用大整数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!