 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Thu Jul 27, 2006 9:10 am Post subject: pure virtual function calls / optimization |
|
|
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
|
Posted: Thu Jul 27, 2006 9:10 am Post subject: Re: pure virtual function calls / optimization |
|
|
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
|
Posted: Thu Jul 27, 2006 9:11 am Post subject: Re: pure virtual function calls / optimization |
|
|
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 |
|
 |
|
|
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
|
|