什么是可以在GCC声明静态数组的最大尺寸? [英] What is the maximum size of static array that can be declared in GCC?

查看:360
本文介绍了什么是可以在GCC声明静态数组的最大尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定它的?这是否取决于编译/建筑/主机系统上?

例如:

  int数组[0x8000000000000000]

有关此行中的x86_64位系统GCC输出:

 错误数组数组的规模过大。


解决方案

通过静态数组,我想,你的意思是一个固定长度的数组(静态分配的,如 int数组[SIZE] ,而不是动态分配)。数组的大小限制应取决于声明数组的范围。


  • 如果您已声明阵列中的局部范围内(有些程序内),大小限制由堆栈大小决定的。

  • 如果GCC在Linux上运行,栈的大小是由一些环境变量确定。使用的ulimit -a 来查看和的ulimit -s STACK_SIZE 修改堆栈大小。

  • 如果GCC在Windows上(如MinGW的)运行,可以通过gcc的-Wl指定堆栈大小, - 栈,STACK_SIZE

  • 如果您已宣布全球范围内的数组,数组存储数据或BSS段(基于阵列是否已初始化或初始化分别)。数据并BSS段的大小是由底层的操作系统决定的。

  • 如果您已声明在静态作用域数组(如静态int数组[SIZE] ),同样,阵列存储数据或BSS部分(根据是否该阵列被初始化或分别未初始化)。数据并BSS段的大小是由底层的操作系统决定的。

How its determined ? Does this depend on the compiler/Architecture/Host system ?

Example:

int array[0x8000000000000000]; 

For this line in a x86_64 bit system GCC outputs:

Error "size of array 'array' is too large".

解决方案

By static array, I assume, you mean a fixed length array (statically allocated, like int array[SIZE], not dynamically allocated). Array size limit should depend on the scope of the array declared.

  • If you have declared the array in local scope (inside some routine), size limit is determined by stack size.
  • If gcc is running on linux, the stack size is determined by some environment variable. Use ulimit -a to view and ulimit -s STACK_SIZE to modify the stack size.
  • If gcc is running on windows (like MinGW), stack size can be specified by gcc -Wl,--stack, STACK_SIZE.
  • If you have declared the array in global scope, the array is stored in DATA or BSS section (based on whether the array is initialized or uninitialized respectively). The DATA and BSS section size are determined by underlying OS.
  • If you have declared the array in static scope (like static int array[SIZE]), again, the array is stored in DATA or BSS section (based on whether the array is initialized or uninitialized respectively). The DATA and BSS section size are determined by underlying OS.

这篇关于什么是可以在GCC声明静态数组的最大尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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