本文介绍了分配大(5000+)数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上的应用程序的工作是有三种可能的大小为数据输入:

I am working on an application were there are three possible sizes for the data entered:


  • 小:1000元

  • 中等= 5000元

  • 大= 500000元

问题是,我不能分配的大阵。看来,大小大于5000是不能接受的。

The problem is that I can't allocate the large array. It seems that a size larger than 5000 is not accepted.

我得到一个运行时错误,当我做到以下几点:

I get a run time error when I do the following:

long  size=1000;
char ch;
int arr[size];
ch=getch();

if(ch==..)
  size=...;

1000和5000尺寸看起来做工精细,但我怎样才能使500K大小的​​数组,以这种方式?

Sizes of 1000 and 5000 seem to work fine, but how can I make an array of size 500k in this way?

推荐答案

您堆栈不能容纳那么多的数据。你必须在堆上分配大数组如下:

Your stack can't hold that much data. You have to allocate big arrays on the heap as follows:

int *array = malloc (sizeof(int)*size);

由于PMG指出,记得要释放你的记忆,一旦你做了。

As pmg pointed out remember to free your memory once your done.

free(array);

这篇关于分配大(5000+)数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 04:49