Re: 'global' data
* forums_mp@hotmail.com:
As Jeff Schwab noted, namespace const variables are by default static.
Each separate translation unit will get their own copy of the
variable. As you probably won't be taking its address, and with basic
constant propagation optimizations, the value will probably be
expanded inline into the code where used, taking up no space for the
variable, and probably less space overall with this approach.
(Presuming that a double takes less space than a loaddouble + address
instruction in the architecture.)- Hide quoted text -
For starters, thanks to all who responded here (certainly cleared up
alot of misinfo that I was carrying around in my head).
Work with me here: "/basic/ constant propagation optimization". QOI
issue I suppose, nonetheless there's no compiler flags that i need to
set to alert GCC (3.4.6 is what I'm using). Hey! I want 'constant
propagation optimization'.
At present a view of the elf output reveals that each translation unit
has a copy of the member variable at global scope.
But are those discardable records or not?
Anyway, if you want to code the discardable thing explicitly you can use the
template const tric:
template< typename Dummy >
struct Math_
{
static double const pi;
};
template< typename Dummy >
double const Math_<Dummy>::pi = 3.14;
typedef Math_<void> Math;
// Here use Math::pi. There's only one in whole program.
Cheers & hth.,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!