In my code design, I've included a lot of constants. When a new object is created, is memory allocated for that object's constants, or is it stored permanently in a single instance, like a static variable is? In terms of memory storage, where exactly do static items end up?
In other words, if I define 100 objects, will there be 100 copies of the same constant value?
If they are defined in static memory (wherever that is), and I would expect that they are, does accessing them require the computer to switch memory pages? Is there a performance hit for constantly accessing constants instead of variables?
Thanks
Ares
Constants have no storage location at runtime. All access to constant identifiers results in the literal value of that constant replacing the identifier when the code is compiled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With