Does the maximum value of the array size exist?

Asked 2 years ago, Updated 2 years ago, 44 views

Debugging the following code causes stack overflow. By any chance, does a static array have the maximum size of the array that can be declared?

void main()
{
      int StaticDoubleArray1[2500][2500] = { 0 };

}

c array

2022-09-22 15:08

2 Answers

https://www.clien.net/service/board/kin/4098266

I expect it to be different depending on the hardware and the compiler To write code that can be compiled in any environment, We need to declare the number of arrays at the right level and do dynamic assignments


2022-09-22 15:08

This issue is a stack size issue, not a static array size issue.

Regional variables are stored using a space called stack, and under the limitation of visual c++, the default stack size is 1 megabyte.

int StaticDoubleArray1[2500][2500] = { 0 };

The size of the above regional variable is int (4byte assumption) * 2500 * 2500.

That's 2500 x 2500 x 4 = 250000 bytes, which is about 24 megabytes. Therefore, stack overflow occurs.

https://yumere.tistory.com/20

You can increase the stack size by referring to the link above.


2022-09-22 15:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.