在C不能申报规模40万数组 [英] Cannot declare array of size 400000 in C

查看:122
本文介绍了在C不能申报规模40万数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试做以下操作:

#include <windows.h>
#include <stdio.h>
#define N 400000

void main() {
    int a[N];
}

我得到一个计算器例外。我的电脑主内存6GB的,所以我不能使用它的所有行动。我该如何解决这个问题?我在Windows 7上使用VS 2008和用C编码。

I get a stackoverflow exception. My computer has 6GB of main memory so I cant be using it all up. How do I solve this problem? I using VS 2008 on Windows 7 and coding in C.

推荐答案

你被允许使用的永远不会是主内存的全额堆栈大小的量。

The amount of stack size you're allowed to use is never going to be the full amount of main memory.

您可以使用此标志设置堆栈大小,可呈现默认为1MB。要存储40万整数你至少需要1.526 MB。

You can use this flag to set the stack size--which defaults to 1MB. To store 400,000 ints you'll need at least 1.526 MB.

为什么不在堆上,而不是堆栈分配此?

Why not allocate this on the heap instead of the stack?

这篇关于在C不能申报规模40万数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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