We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi all,
what would be the best way to init a huge array, which will never change his values? Will the array affect the stack if I use const aray[][] or should I use static const array[][]?
What would be the best way if the array is not const during the whole program?
best regards Hans
I am not sure if I understand the above statement.
If the static keyword is not used, then the compiler is free to allocate space for the variable in whatever way it allocates space for non-persistent variables (e.g. on the stack, using memory overlaying, in registers, using static allocation, whatever). This means that if there's a stack, then the variable can end up there, or not, depending on the compiler.
If the static keyword is used, the compiler must allocate space in the way it does for persistent variables. This excludes putting it on the stack.
(And yes, I've just recently seen that the compiler I use did put a large const array on the stack, ironically by copying values stored elsewhere in memory to the stack. It only stopped doing that after I made the array static const.)