Original Post
🔒 Locked
Hardcoded arrays?
Advertisement
well, if you make the array definition local to a function, then the array will have to be initialized on the stack each time you make the function call (in most cases). Or, you could define the array globally/statically and it will only be initialized once... but then the cache miss to access the static memory might cost as much as the time spent initializing the array.
So it depends :)
The best case is if for each compilation unit, the compiler can resolve the value at compile time. What conversions for enumerations exactly are you trying to create?
So it depends :)
The best case is if for each compilation unit, the compiler can resolve the value at compile time. What conversions for enumerations exactly are you trying to create?
Quote:
Original post by Axiverse
Isn't that still a intilized global variable?
If it's the best there is... i guess it'll have to do.. =)
Even a "hardcoded" array has to be initialized - if you mean the difference between "setting them at run time" and "setting them at compile time" - well, the values of my_int_array will be read from the EXE just as a const int would.
That said, if using classes with non-trivial initialization semantics, those will be run at run-time.
Adding the const keyword will allow the compiler to replace "my_int_array[5]" with 4 throughout the code where this is advantageous, taking advantage of the fact that my_int_array[5] can't change in value (unless you add the volatile keyword as well - which is legal - meaning: "The users of this code can't modify the value, but it can be changed externally".
How much time do you think you'll be able to save?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement