简体   繁体   English

C中静态分配的数组大小的限制

[英]Limit of statically allocated array size in C

This is a memory-allocation related question in C. I have a number (let's say 5) 2-dimensional arrays of floats. 这是C语言中与内存分配有关的问题。我有多个(假设5个)浮点数二维数组。 Each of the arrays is 60x60. 每个阵列为60x60。

Theoretically, this information represents static data that is not going to be changed after it is initially calculated. 从理论上讲,此信息表示在初始计算后将不会更改的静态数据。

Should this be stored as a static size array or is this big enough for being allocated dynamically? 应该将其存储为静态大小数组还是足够大以进行动态分配? I suppose I am unclear about the size of the stack and if declarations such as arr [60][60] will be stored exclusively in the DATA section. 我想我不清楚堆栈的大小以及是否将诸如arr [60][60]声明仅存储在DATA节中。 Does this depend on the machine or on the code itself? 这取决于机器还是代码本身? Since stack memory usually corresponds to high level cache, what is the size limit for this on, let's say Intel i5 line of machines? 由于堆栈内存通常对应于高级高速缓存,因此它的大小限制是多少,比如说Intel i5系列机器?

I understand that this is very broad question, so I will gladly take references to credible background sources. 我知道这是一个非常广泛的问题,因此我很乐意参考可靠的背景资料。

So it's 5 times 60 times 60 times 4 (size of float )? 所以它是5乘以60乘以60乘以4( float )? That's only 72000 bytes. 只有72000个字节。 Small enough to declare it as "static" compile-time arrays/matrices, even in quite small embedded systems. 足够小,即使在很小的嵌入式系统中,也可以将其声明为“静态”编译时数组/矩阵。 And if you're on a normal PC (Windows, Linux, OSX) then the stack is at least a megabyte, maybe as much as 8 MB, so no problem there either. 而且,如果您使用的是普通PC(Windows,Linux,OSX),则堆栈至少为一个兆字节,可能高达8 MB,因此那里也没有问题。 Also, on a reasonable modern computer (ie one made the last six-seven years or so) copying of 72000 bytes is still fast enough for you to not notice it. 同样,在一台合理的现代计算机(即最近六到七年制造的计算机)上,复制72000字节仍然足够快,您可能不会注意到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM