Top DevX Stories
Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Search the forums:

Go Back   DevX.com Forums > DevX Developer Forums > C++

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 10-26-2009, 11:23 AM
hendrixj hendrixj is offline
Registered User
 
Join Date: Oct 2007
Posts: 240
virtual overhead

I started out with a class that need some functions to be virtual for the usual reasons. As the code was scrubbed, that reason went away. It led me to a question: If a class (that does not inherit from anyone, so it is a base class) uses the virtual keyword for a function that never gets overridden in a derived class (since there are no derived classes), should I expect the "virtual" keyword to force a vtable lookup when the function is called?
Put another way, should I expect the compiler to recognize that a vtable for is not necessary and do the binding directly?

John
Reply With Quote
  #2  
Old 10-27-2009, 01:07 PM
Danny's Avatar
Danny Danny is offline
Super Moderator
 
Join Date: Nov 2003
Posts: 3,948
Sadly, the answer is yes, but only if you call a member function through a pointer or a reference. A call to a member function via an object is always resolved statically.
Clever compilers and compilers that do whole program analysis are able to optimize away vtable lookup when the function called through a pointer/reference can be resolved statically but don't count on that. So the real question is: does your code call the member functions through pointers or references?
Notice that in any event, virtual implies a vtable per class so the space overhead is inevitable.
__________________
Danny Kalev
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pure Virtual functions ami C++ 2 12-02-2006 04:29 PM
Pointer to virtual memfunction behaving surpriseingly. sudipsand C++ 4 10-28-2005 12:00 AM
non virtual destructor is called drkybelk C++ 3 03-17-2005 09:27 AM
files langevin .NET 1 09-13-2002 09:57 PM
WebFroms and Virtual Directories Madhu ASP.NET 2 05-08-2002 12:36 PM


All times are GMT -4. The time now is 09:59 PM.


Sponsored Links



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.