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
> Or is there no disadavantage if I don't use static?
Too many negations. I hope I got your question right :-)
By default, the RealView compiler tries to inline functions within the same compile unit at certain optimization levels. Non-static functions will also be made available as regular functions since they might be called externally. The compiler cannot know whether or not this is the case.
A non-static function might therefore cause an unnecessary overhead if it is guaranteed to be used only within the same compile unit it has been defined in.
Regards Marcus http://www.doulos.com/arm/
> It is possible that the array ends up on the stack if static is not used.
I am not sure if I understand the above statement.
Does that mean?
A huge array without the "static" keyword, is some regular local variables, when it is be used, it will consume the stack space, then the small stack corrupted.
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.)