C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

pure virtual function calls / optimization

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Thu Jul 27, 2006 9:10 am    Post subject: pure virtual function calls / optimization Reply with quote



Hi

I wonder if their will be a performance penalty in the following
situation due to virtual function calls:

class Interface
{
public:
virtual void methodA() = 0;
virtual void methodB() = 0;
virtual void methodC() = 0;
virtual void methodD() = 0;
};

class Implementation
{
public:
void methodA() { /* do someting */ }
void methodB() { /* do someting */ }
void methodC() { /* do someting */ }
void methodD() { /* do someting */ }

};

IMHO there is no need for class Implementation to have a virtual method
table, since there is just one possibility for every method. It's a
special case, I know. Other derived classes may have virtual functions.
What do current compilers do? Are there optimizations for such
situations or did I just miss something?

regards,
Alex
Back to top
Guest






PostPosted: Thu Jul 27, 2006 9:10 am    Post subject: Re: pure virtual function calls / optimization Reply with quote



alexander.stippler@uni-ulm.de schrieb:

Quote:
Hi

I wonder if their will be a performance penalty in the following
situation due to virtual function calls:

class Interface
{
public:
virtual void methodA() = 0;
virtual void methodB() = 0;
virtual void methodC() = 0;
virtual void methodD() = 0;
};

class Implementation
{
public:
void methodA() { /* do someting */ }
void methodB() { /* do someting */ }
void methodC() { /* do someting */ }
void methodD() { /* do someting */ }

};

IMHO there is no need for class Implementation to have a virtual method
table, since there is just one possibility for every method. It's a
special case, I know. Other derived classes may have virtual functions.
What do current compilers do? Are there optimizations for such
situations or did I just miss something?

regards,
Alex

Sorry, of course the Implementation class is publicly derived from the
Interface class.

class Implementation
: public Interface
{
//...
};
Back to top
Ian Collins
Guest





PostPosted: Thu Jul 27, 2006 9:11 am    Post subject: Re: pure virtual function calls / optimization Reply with quote



alexander.stippler@uni-ulm.de wrote:
Quote:
Hi

I wonder if their will be a performance penalty in the following
situation due to virtual function calls:

class Interface
{
public:
virtual void methodA() = 0;
virtual void methodB() = 0;
virtual void methodC() = 0;
virtual void methodD() = 0;
};

class Implementation
{
public:
void methodA() { /* do someting */ }
void methodB() { /* do someting */ }
void methodC() { /* do someting */ }
void methodD() { /* do someting */ }

};

IMHO there is no need for class Implementation to have a virtual method
table, since there is just one possibility for every method. It's a
special case, I know. Other derived classes may have virtual functions.
What do current compilers do? Are there optimizations for such
situations or did I just miss something?

The may well be an over head, but it will be small. Whether or not the

compiler can perform any optimisations such as inlining depends on the
compiler and the use of the functions.

--
Ian Collins.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.