无法分配超过一百万的整数 [英] Can't allocate more than a million integers

查看:116
本文介绍了无法分配超过一百万的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想时间和比较排序算法。从我的理解:的sizeof(INT) 4个字节,因此 int数组[一百万]; 收益率(4 )百万字节这是4000 KB或约4MB

I'm trying to time and compare sorting algorithms. From what I understand: sizeof(int) is 4 bytes, therefore int array[one million]; yields (4) million bytes which is 4,000 kb or 4mb roughly.

那么,为什么我不能?我是pretty确保我有更多。 2GB为precise。

So why can't I? I'm pretty sure I have more. 2gb to be precise.

我用gcc如果这意味着什么。

I'm using gcc if that means anything.

推荐答案

您不能有许多整数堆栈。

You can't have that many integers on stack.

试用阵列分配上的堆空间。

Try allocating space on heap for your array.

int *array = malloc(1000000*sizeof(int));
// if array is not null, then you have an array with 1,000,000 ints.

您与您的排序算法完成后,你释放数组:

After you are done with your sorting algorithms, you free the array:

free(array); // frees memory allocated before

这篇关于无法分配超过一百万的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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