F
forums_mp
Given a file global constants.h such that:
//global_constants.h
namespace GlobalConstants {
int const X = 5;
double const PI = 3.141 ;
}
During an email exchange with a coworker the coworker made the claim
that the constants will be repeated in memory for each code object
file that includes it. So if there's alot of constants that are used
everywhere, I will consume lots of memory.
Now consider a class X such that:
# include "global_constants.h"
class X {
public :
X ()
void do_work()
{ int const dummy = GlobalConstants::X ; }
};
Two things:
a) I thought elimination of unused symbols was guaranteed (couldn't
confirm this in the standard though). IOW PI will be non-existent in
the object file for X.
b) I've often understood that no 'memory' will be consumed anywhere
since GlobalConstants::X will be replaced with the value 5. Memory is
consumed within the namespace for sizeof ( int ) and sizeof (double)
but that's the extent of it for the GlobalConstants.
Am I off on a) and b) above? Thanks in advance
//global_constants.h
namespace GlobalConstants {
int const X = 5;
double const PI = 3.141 ;
}
During an email exchange with a coworker the coworker made the claim
that the constants will be repeated in memory for each code object
file that includes it. So if there's alot of constants that are used
everywhere, I will consume lots of memory.
Now consider a class X such that:
# include "global_constants.h"
class X {
public :
X ()
void do_work()
{ int const dummy = GlobalConstants::X ; }
};
Two things:
a) I thought elimination of unused symbols was guaranteed (couldn't
confirm this in the standard though). IOW PI will be non-existent in
the object file for X.
b) I've often understood that no 'memory' will be consumed anywhere
since GlobalConstants::X will be replaced with the value 5. Memory is
consumed within the namespace for sizeof ( int ) and sizeof (double)
but that's the extent of it for the GlobalConstants.
Am I off on a) and b) above? Thanks in advance