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

E

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-lite/virtual-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.
 
V

Victor Bazarov

er said:
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-lite/virtual-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
 
E

er

er said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top