473,406 Members | 2,707 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,406 software developers and data experts.

is speed of exec of a member function always impacted by an extra layer in a class hierarchy?

er
hi,

what if i have
class B{public: virtual void f()const=0;};
class D0: public B{/*empty */};
class D1: public B{/*empty */};

is the execution of f slower for
class A: public D0{public: virtual void f()const;}
than it is for
class A: public B{public: virtual void f()const;}
given that their implementations for f are the same?

i'm aware that
http://www.parashift.com/c++-faq-lit...functions.html says:
"The compiler creates a v-table for each class that has at least one
virtual function."
but the reason i have a doubt is that D0 and D1 are used only to
specify two abstract sub-hierarchies.

Sep 20 '07 #1
3 1060
er wrote:
what if i have
class B{public: virtual void f()const=0;};
class D0: public B{/*empty */};
class D1: public B{/*empty */};

is the execution of f slower for
class A: public D0{public: virtual void f()const;}
than it is for
class A: public B{public: virtual void f()const;}
given that their implementations for f are the same?
Should be no difference.
i'm aware that
http://www.parashift.com/c++-faq-lit...functions.html says:
"The compiler creates a v-table for each class that has at least one
virtual function."
but the reason i have a doubt is that D0 and D1 are used only to
specify two abstract sub-hierarchies.
Shouldn't matter.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 20 '07 #2

"er" <er***********@gmail.comwrote in message news:11**********************@57g2000hsv.googlegro ups.com...
hi,

what if i have
class B{public: virtual void f()const=0;};
class D0: public B{/*empty */};
class D1: public B{/*empty */};

is the execution of f slower for
class A: public D0{public: virtual void f()const;}
than it is for
class A: public B{public: virtual void f()const;}
given that their implementations for f are the same?
[snip]

Look at
http://article.gmane.org/gmane.comp.....perfometer/66

--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Sep 21 '07 #3
er
On Sep 21, 12:50 pm, "Alex Vinokur" <ale...@users.sourceforge.net>
wrote:
"er" <erwann.rog...@gmail.comwrote in messagenews:11**********************@57g2000hsv.go oglegroups.com...
hi,
what if i have
class B{public: virtual void f()const=0;};
class D0: public B{/*empty */};
class D1: public B{/*empty */};
is the execution of f slower for
class A: public D0{public: virtual void f()const;}
than it is for
class A: public B{public: virtual void f()const;}
given that their implementations for f are the same?

[snip]

Look athttp://article.gmane.org/gmane.comp.lang.c++.perfometer/66

--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
interesting. thanks.


Sep 21 '07 #4

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

Similar topics

3
by: Mark Turney | last post by:
Problem: I have a vector full of two different derived class objects (class B and class C) that are derived from the same base class A. I want to loop through vector and invoke a member function...
37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
23
by: Mark Dickinson | last post by:
I have a simple 192-line Python script that begins with the line: dummy0 = 47 The script runs in less than 2.5 seconds. The variable dummy0 is never referenced again, directly or indirectly,...
7
by: Michael | last post by:
I'm writing an application that decodes a file containing binary records. Each record is a particular event type. Each record is translated into ASCII and then written to a file. Each file contains...
7
by: The|Godfather | last post by:
Hi everybody, I read Scotte Meyer's "Effective C++" book twice and I know that he mentioned something specific about constructors and destructors that was related to the following...
3
by: benben | last post by:
I have always found Stroustrup's paper on generalized member function wrapper (http://www.research.att.com/~bs/wrapper.pdf) an interesting one. Recently I started to play with it. As I tried to put...
7
by: v4vijayakumar | last post by:
Is it possible to implement member object's virtual functions, in the containing class? If not, is it possible to simulate this behavior? ex: class test { protected: virtual void fun() = 0;...
4
by: RSH | last post by:
Hi, I have a situation where I have a class which manages different data connections. In trying to enforce encapsulation I have a member field called connection which could be a type of...
11
by: Gabriel de Dietrich | last post by:
Hi all! Just out of curiosity: Is there any way to get the address of a particular virtual member function given an object? Some code to make things more clear... class A { public: A() { }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.