Constant singleton object initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

Assume the following very similiar class declarations:

class A {
public:
	int x;
};

class B {
public:
	inline B(int _x) : x(_x) {}
	int x;
};

class C {
public:
	inline C(int _x) : x(_x) {}
	virtual ~C(void) {}
	int x;
};

Now assume the following definitions:

const A a={42};
const B b(42);
const C c(42);

If I compile this, a will end up in the ".rodata" section with the correct 
initialization value written to the segment, while b and c end up in BSS and 
are initialized at runtime. While I think that at least b could reasonably be 
put into rodata, I am more interested in c -- is there a fundamental reason 
why this is not possible? (i.e. is this an artifact of the presence of a 
constructor, or does the virtual methods table pointer affect initialization 
as well?)

I have a program which declares a large amount of singleton objects in this 
way, I would like them to have virtual methods, and all constructors are 
empty. The problem is that the initialization of the objects is really eating 
into the start-up overhead. I could replace the classes with virtual methods 
with struct containing function-pointer tables, but this appears very 
un-C++-ish...

Thanks and best regards
-- 
Mathematicians stand on each other's shoulders while computer scientists stand 
on each other's toes.
-- Richard Hamming

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux