I\'m somewhat new to programming in general and I\'ve run into an issue with declaring 3D and 4D arrays. I have several declarations like this at the start of my main function,
Assuming for simplicity that sizeof(string) == 2
(it's probably more), you're trying to allocate (64^3)*9*2 bytes on the stack. That comes out to 4,718,592 bytes, or approximately 4.5 MiB. Most likely, you just don't have 4.5 MiB available on your stack.
Since these variables are declared in main()
, you have two possible solutions:
Declare them static
.
Declare them outside main()
, as global variables.
This will cause them to be allocated before the program starts, rather than on the stack. The only difference between the two approaches is whether they'll be visible in other functions.
There may also be a way to tell your compiler that the program needs more stack space, but I think making them static is probably the better solution here. If they were in a function other than main()
though, you'd probably need to do something else.