473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Run-time overhead for multiple inheritance

Hi,

I would like to follow Stroustrup's advice of separating an object
interface (abstract class) from an object implementation (concrete
class), See Section 15.2.5 in Stroustrup 3rd Edition.

Specifically, I want to create an abstract base class that defines an
object interface:

class myAbstractClass
{
virtual func1() = 0;
virtual func2() = 0;
virtual func3() = 0;
};

I would then have one or more concrete classes that override these
virtual functions to implement this interface.

class usefulClass
: public myAbstractClass // interface
, protected myImplClass1 // implementation of func1() and func2()
, protected myImpClass2 // implementation of func3()
{
...
};

Essentially usefulClass glues together implementation classes that
fill out the interface defined by the abstract class. I would like to
know how to quantify the run-time overhead for this? Is it greater
then the run-time overhead of just inheriting a single concrete base
class?

Thanks for any help,

Michael
Jan 4 '08 #1
2 2595
mm***********@gmail.com wrote:
I would like to follow Stroustrup's advice of separating an object
interface (abstract class) from an object implementation (concrete
class), See Section 15.2.5 in Stroustrup 3rd Edition.

Specifically, I want to create an abstract base class that defines an
object interface:

class myAbstractClass
{
virtual func1() = 0;
virtual func2() = 0;
virtual func3() = 0;
};

I would then have one or more concrete classes that override these
virtual functions to implement this interface.

class usefulClass
>public myAbstractClass // interface
, protected myImplClass1 // implementation of func1() and func2()
, protected myImpClass2 // implementation of func3()
{
...
};

Essentially usefulClass glues together implementation classes that
fill out the interface defined by the abstract class. I would like to
know how to quantify the run-time overhead for this? Is it greater
then the run-time overhead of just inheriting a single concrete base
class?
How to quantify, eh? I would say, write two programs, one with MI
and the other without it. They should be identical in any other
respect, of course. Then profile them both. The difference could
then be attributed to MI.

Is it greater than just inheriting, you ask? To answer this question
you need to quantify "just inheriting" and then compare the results
to inheriting from multiple base classes. And since none of that is
really important (nor expected to ever be signifincant enough) for
the development of large systems (the primary purpose of C++, BTW),
you will have wasted your time to find out that such run-time overhead
doesn't exist, it's a rumour probably spread by Visual Basic people.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 4 '08 #2
On Jan 4, 6:52 pm, "Alf P. Steinbach" <al...@start.nowrote:
* mmcgarry.w...@gmail.com:
I would like to follow Stroustrup's advice of separating an object
interface (abstract class) from an object implementation (concrete
class), See Section 15.2.5 in Stroustrup 3rd Edition.
Specifically, I want to create an abstract base class that defines an
object interface:
class myAbstractClass
{
virtual func1() = 0;
virtual func2() = 0;
virtual func3() = 0;
};
I would then have one or more concrete classes that override these
virtual functions to implement this interface.
class usefulClass
: public myAbstractClass // interface
, protected myImplClass1 // implementation of func1() and func2()
, protected myImpClass2 // implementation of func3()
{
...
};
The standard mixin pattern, in sum. Except that in the
classical idiom 1) the implementation classes would generally
inherit from the interface as well, so virtual inheritance is
called for, and 2) the inheritance of the implementation classes
should be private, not protected.
Essentially usefulClass glues together implementation classes that
fill out the interface defined by the abstract class. I would like to
know how to quantify the run-time overhead for this? Is it greater
then the run-time overhead of just inheriting a single concrete base
class?
The way you write it, using wrapper functions, no, a wrapper
has the same overhead anyway.
The way he writes it is probably preferable for simple cases,
but it doesn't always work. Suppose that func1() needs to call
func3() in some cases.
Letting the compiler tie the implementations to the interface, i.e.
using virtual inheritance (Java-style implementation inheritance), you
may incur some slight overhead because a diamond inheritance requires
more complicated virtual function address lookup.
Just a nit: the virtual function address lookup is exactly the
same. There is often a small performance loss because the
calculation of the this pointer is slightly more complicated,
and there is also often a small additional space overhead as
well.
To quantify this possible overhead in the second case, measure.
By the way, it's generally not a good idea to split
implementations of a single interface in different classes.
That indicates a design error either for the interface or the
implementation classes or both.
In a lot of cases, perhaps. There are cases where the mixin
pattern is just the thing, however. It's a natural when the
"customization" can be categorized in several dimensions.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jan 4 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ed | last post by:
Hello, I took a course in asp about 2 years ago and I was practicing with IIS 5.0. Then I put it down for a while. Now trying to get back to it. I can't run asp files from subdirectories of...
4
by: Primo | last post by:
Hi, This problem has been frustrating me for days and I hope you experts can help me out. I am trying to run a command, which I would normally run from the command line, from within my C#...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
13
by: Bob Day | last post by:
Using vs2003, vb.net I start a thread, giving it a name before start. Code snippet: 'give each thread a unique name (for later identification) Trunk_Thread.Name = "Trunk_0_Thread" ' allow...
3
by: emman_54 | last post by:
Hi every one, I am trying to run a batch file using my asp.net application. I am using the Process class to run the batch file. When I run my web application, In the task manager, i could see...
19
by: Bryan | last post by:
How can i run a bit of code straight from the IDE? Right now i make a temporary button and put the code behind that, then i run debug mode and click on the button. Is there a way to highlight...
9
by: Brett Wesoloski | last post by:
I am new to VS2005. I changed my program.cs file to be a different form I am working on. But when I go to run the application it still brings up the form that was originally declared as new. ...
7
by: Lee Crabtree | last post by:
I remember when I was first getting into .NET Forms programming that there was a rather emphatic rule about not constructing a form before calling Application.Run with it. So this: ...
8
by: David Thielen | last post by:
Hi; In our setup program how do I determine if I need to run "aspnet_regiis –i" and if so, is there an API I can calll rather than finding that program on the user's disk and calling it? --...
3
by: traceable1 | last post by:
Is there a way I can set up a SQL script to run when the instance starts up? SQL Server 2005 SP2 thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.