为什么248x248最大的双维数组的大小,我可以申报? [英] Why is 248x248 the maximum bi dimensional array size I can declare?

查看:103
本文介绍了为什么248x248最大的双维数组的大小,我可以申报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想在C申报了256×256阵列不幸的是程序问题,我每一次我试着甚至宣布尺寸(整数)的数组,我运行我的程序,它意外终止。有什么建议么?我没有尝试过的内存分配,因为我似乎无法理解它如何与多维数组(随意引导我通过它,虽然我是新的C)。需要注意的另一个有趣的事情是,我可以声明在C 248x248阵列没有任何问题,但没有大的。

I have a program problem for which I would like to declare a 256x256 array in C. Unfortunately, I each time I try to even declare an array of that size (integers) and I run my program, it terminates unexpectedly. Any suggestions? I haven't tried memory allocation since I cannot seem to understand how it works with multi-dimensional arrays (feel free to guide me through it though I am new to C). Another interesting thing to note is that I can declare a 248x248 array in C without any problems, but no larger.

dims = 256;  
int majormatrix[dims][dims];

与编译:

gcc -msse2 -O3 -march=pentium4 -malign-double -funroll-loops -pipe -fomit-frame-pointer -W -Wall -o "SkyFall.exe" "SkyFall.c"

我使用赛特323(不知道如何检查GCC版本)。

I am using SciTE 323 (not sure how to check GCC version).

推荐答案

有三个地方可以分配使用C数组:

There are three places where you can allocate an array in C:


  • 自动的存储器(通常被称为在栈上)

  • 动态的内存(的malloc / 免费)或

  • 静态的内存(静态关键字/全球空间)。

  • In the automatic memory (commonly referred to as "on the stack")
  • In the dynamic memory (malloc/free), or
  • In the static memory (static keyword / global space).

只有自动存储器具有对分配的量稍微严重的限制(即,除了由操作系统设置的限制);动态和静态分配可能会抢了近尽可能多的空间是由操作系统提供给您的进程。

Only the automatic memory has somewhat severe constraints on the amount of allocation (that is, in addition to the limits set by the operating system); dynamic and static allocations could potentially grab nearly as much space as is made available to your process by the operating system.

,看是否是这种情况最简单的方法是将你的函数外部声明。这将您的阵列转移到静态存储器。如果继续崩溃,他们什么都没有做与你的数组的大小。

The simplest way to see if this is the case is to move the declaration outside your function. This would move your array to static memory. If crashes continue, they have nothing to do with the size of your array.

这篇关于为什么248x248最大的双维数组的大小,我可以申报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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