用C数组的最大尺寸 [英] The maximum size of an array in C

查看:103
本文介绍了用C数组的最大尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,硬件将限制程序执行过程中分配的内存量。不过,我的问题是,不考虑硬件。假设没有限制的内存量,才会有没有限制阵列?

I understand that hardware will limit the amount of memory allocated during program execution. However, my question is without regard to hardware. Assuming that there was no limit to the amount of memory, would there be no limit to the array?

推荐答案

有没有的固定的上限在C数组的大小。

There is no fixed limit to the size of an array in C.

任何单个对象,包括数组对象的大小,是由 SIZE_MAX 限制,类型的最大值为size_t ,这是的sizeof 运算符的结果。 (这不是完全清楚C标准的许可证是否反对比 SIZE_MAX更大字节,但在实践中这种对象不支持;见注)。由于 SIZE_MAX 是由实现决定,而不能由任何程序进行修改,即规定一个上限 SIZE_MAX 的字节任何单个对象。

The size of any single object, including of any array object, is limited by SIZE_MAX, the maximum value of type size_t, which is the result of the sizeof operator. (It's not entirely clear whether the C standard permits objects larger than SIZE_MAX bytes, but in practice such objects are not supported; see footnote.) Since SIZE_MAX is determined by the implementation, and cannot be modified by any program, that imposes an upper bound of SIZE_MAX bytes for any single object.

型的宽度空隙* ,一个通用的指针类型,规定所有的对象的总大小的上限在一个执行中的程序(其可以是大于单个对象的最大尺寸)。

The width of the type void*, a generic pointer type, imposes an upper bound on the total size of all objects in an executing program (which may be larger than the maximum size of a single object).

C标准规定下限,但没有上限,在这些固定的大小。没有标准的C实现可以支持无限大小的物体,但它可以在任何有限尺寸的原则,支持对象。上限是由个别C实现征收,由它们运营环境,并通过物理,而不是语言。

The C standard imposes lower bounds, but not upper bounds, on these fixed sizes. No conforming C implementation can support infinite-sized objects, but it can in principle support objects of any finite size. Upper bounds are imposed by individual C implementations, by the environments in which they operate, and by physics, not by the language.

例如,一个符合标准的实现可以有 SIZE_MAX 等于2 1024 -1,这意味着它可能的原则有对象达179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137215字节。

For example, a conforming implementation could have SIZE_MAX equal to 21024-1, which means it could in principle have objects up to 179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137215 bytes.

祝你好运找到实际支持此类对象的硬件。

Good luck finding hardware that actually supports such objects.

脚注的:没有明确的规则,没有对象可以是比 SIZE_MAX 字节大。你不能在的sizeof 运营商有效地应用到这样一个对象,但像任何其他的运营商,的sizeof 可以溢出;这并不意味着你不能这样的对象上执行操作。但在实践中,任何理智的实施将使为size_t 大到足以重新present它支持任何物体的大小。

Footnote: There is no explicit rule that no object can be bigger than SIZE_MAX bytes. You couldn't usefully apply the sizeof operator to such an object, but like any other operator, sizeof can overflow; that doesn't mean you couldn't perform operations on such an object. But in practice, any sane implementation will make size_t big enough to represent the size of any object it supports.

这篇关于用C数组的最大尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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