Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Static on Multiple Inheritances?

Reply
Thread Tools

Static on Multiple Inheritances?

 
 
Immortal Nephi
Guest
Posts: n/a
 
      04-17-2009
Multiple Inheritances can contain multiple diamond shapes. Can CPU be
very overhead if two indirections and one direct memory are used?

For example.

Create one base class

class A {};

Create tens of derived classes

class B1 : virtual public A {};
class B2 : virtual public A {};
.....
.....
class B20 : virtual public A {};
class B21 : virtual public A {};

Create hundreds of derived classes

class C100 : public B1, public B2, .... public B20, public B21 {};
class C101 : public B1, public B2, .... public B20, public B21 {};
.....
.....
class C200 : public B1, public B2, .... public B20, public B21 {};
class C201 : public B1, public B2, .... public B20, public B21 {};

Finally, create one last derived class
class D : public C100, public C101, .... public C200, public C201
{
public:
void run() {}
};

int main()
{
D d;
d.run();

return 0;
}

You can notice that class D's vtable grows very huge with thousands of
function members and data members. Only client can invoke d.run()
before class D does its own job to invoke thousands of function
members. Class D can be written into library and client includes
library into his source code.

C++ Compiler can compile without any problems if you are very careful
to design and avoid prone errors. CPU's overheads can be very
expensive. It can slow performance while class D is running at run
time.

If you declare static to all one base class and hundreds of derived
classes like singleton, then hundreds of object codes are linked
together into execution program. It can run faster because it uses
only one direct memory without having to use twice indirection with
huge vtable.

Is it worth good design? You don't like to read over millions of
lines in one file scope module. Multiple file scope modules help to
be readability and reduced prone errors.

Thanks...

 
Reply With Quote
 
 
 
 
Michael DOUBEZ
Guest
Posts: n/a
 
      04-17-2009
Immortal Nephi wrote:
> Multiple Inheritances can contain multiple diamond shapes. Can CPU be
> very overhead if two indirections and one direct memory are used?
>
> For example.
>
> Create one base class
>
> class A {};
>
> Create tens of derived classes
>
> class B1 : virtual public A {};
> class B2 : virtual public A {};
> ....
> ....
> class B20 : virtual public A {};
> class B21 : virtual public A {};
>
> Create hundreds of derived classes
>
> class C100 : public B1, public B2, .... public B20, public B21 {};
> class C101 : public B1, public B2, .... public B20, public B21 {};
> ....
> ....
> class C200 : public B1, public B2, .... public B20, public B21 {};
> class C201 : public B1, public B2, .... public B20, public B21 {};
>
> Finally, create one last derived class
> class D : public C100, public C101, .... public C200, public C201
> {
> public:
> void run() {}
> };
>
> int main()
> {
> D d;
> d.run();
>
> return 0;
> }
>
> You can notice that class D's vtable grows very huge with thousands of
> function members


I assume each of your class B defines a new virtual function. Otherwise,
the vtable is not likely to grow.

> and data members.


Data members are not part of vtable.

> Only client can invoke d.run()
> before class D does its own job to invoke thousands of function
> members. Class D can be written into library and client includes
> library into his source code.
>
> C++ Compiler can compile without any problems if you are very careful
> to design and avoid prone errors.


I am not sure "careful" is the adjective I would use to qualify such a
design even as an exercise.

> CPU's overheads can be very
> expensive. It can slow performance while class D is running at run
> time.


Why ? Access to vtable is constant time, the size should not modify
anything (depending on the implementation of vtable by the compiler).

And it is unlikely that the vtable will be even used. At least, not in
the example you give: each object is identified and the compiler will
use the proper function call.

> If you declare static to all one base class and hundreds of derived
> classes like singleton, then hundreds of object codes are linked
> together into execution program.


But you have only one instance of them. Not what one usually wants.

> It can run faster because it uses
> only one direct memory without having to use twice indirection with
> huge vtable.


No.

> Is it worth good design?


No.

> You don't like to read over millions of
> lines in one file scope module.


That's not what inheritance is about.

> Multiple file scope modules help to
> be readability and reduced prone errors.


No it doesn't. It serves other qualities such as modularity,
separability or configurability.

> Thanks...


What is your question about diamond shape inheritance ?

--
Michael
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Non-static aggregate with multiple choices has non-static otherschoice." rickman VHDL 5 03-30-2013 11:06 PM
PIX public/24 ip static mapping means 256 times interfaces static maps? Nieuws Xs4all Cisco 2 05-26-2005 06:25 PM
PIX public/24 ip static mapping means 256 times interfaces static maps? Nieuws Xs4all Cisco 0 05-26-2005 11:07 AM
Static classes with static members Ben ASP .Net 3 06-01-2004 07:43 PM
Static vs. non-static connection Natan ASP .Net 8 05-26-2004 08:21 AM



Advertisments