What is the runtime overhead of class inheritance level.
what can be the implication of depth of 10 to 20 level deep inheritance.
Is there any performance hit with such deep level of inheritance.
Please adivice.

07-14-2010, 07:37 AM

JosAH

Quote:

Originally Posted by devaru2003

What is the runtime overhead of class inheritance level.
what can be the implication of depth of 10 to 20 level deep inheritance.
Is there any performance hit with such deep level of inheritance.
Please adivice.

The depth of the inheritance tree doesn't matter because when a class is loaded its parent class is already loaded and that one is the only class needed to set up a "virtual function table". i.e. a copy of that table is made and the overrriding method addresses are filled in.

kind regards,

Jos

07-14-2010, 08:18 AM

devaru2003

Thanks Jos for Quick response
What I am wondering is as I keep on adding each new level of hierarchy, the overhead is constant or it is increasing per level of inheritance

07-14-2010, 08:25 AM

JosAH

Quote:

Originally Posted by devaru2003

Thanks Jos for Quick response
What I am wondering is as I keep on adding each new level of hierarchy, the overhead is constant or it is increasing per level of inheritance

As I wrote in my previous reply: the depth of the inheritance tree doesn't matter. Just more classes need to be loaded if you want to load a deeply nested (inheritane wise) class. The loading per class doesn't slow down when the depth of the class increases.

kind regards,

Jos

07-14-2010, 09:42 AM

devaru2003

tHANKS jOS

This is really helpful

07-14-2010, 09:51 AM

masijade

Instantiating instances of the classes will be affected though, depending on what the constructors of those classes do. As long as none of them do anything "exotic" it is negligible (unless you're instantiating millions of them), but just keep in mind that when you instatiate an object a constructor will be executed in every one of those classes in order to facilitate the instantiation.