Connecting Tech Pros Worldwide Help | Site Map

How many virtual functions before needing dispatch tables?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 09:52 PM
The Stevemeister
Guest
 
Posts: n/a
Default How many virtual functions before needing dispatch tables?

Hi, I have an entity class (from a rendering engine)
with about 100 functions now that are virtual. So far
no slowdowns, but since I've done alot of work with
OWL and MFC over the years, and I know that when the
virtual functions get too many, OWL and MFC result
to dispatch tables.

Question is, at what point do I say, "At what point
do I switch to dispatch tables?"

Thanks,
--------------------
Steven E.
www.rick-n-steve.com


  #2  
Old July 22nd, 2005, 09:52 PM
Ivan Vecerina
Guest
 
Posts: n/a
Default Re: How many virtual functions before needing dispatch tables?

"The Stevemeister" <none@none.com> wrote in message
news:WSGld.18319$xB1.16975@fe33.usenetserver.com.. .[color=blue]
> Hi, I have an entity class (from a rendering engine)
> with about 100 functions now that are virtual. So far
> no slowdowns, but since I've done alot of work with
> OWL and MFC over the years, and I know that when the
> virtual functions get too many, OWL and MFC result
> to dispatch tables.
>
> Question is, at what point do I say, "At what point
> do I switch to dispatch tables?"[/color]

You shouldn't really worry about the number of virtual
functions alone - as long as each of the concrete
implementations of your base class implements/overrides
most of these functions.

The problem for MFC/OWL is that there are hundreds
of messages that need to be handled by a widget,
AND most of the many subclasses that exist only need
to implement/override a few of these messages.
The drawback of virtual tables then is that, even
if a subclass overrides a single virtual function,
it needs to have its own copy of a complete virtual
table with hundreds of (unchanged) entries. This is
what ends up being expensive.

Another issue with virtual tables is the fragile
base class problem: if a virtual function is added
or removed from the base class, all the subclasses
need to be recompiled (and their vtbls rebuilt).
This is only a real problem if, as OWL/MFC, you
distribute a library in binary form only, and others
need to subclass its contents.

Unless either of these problems is relevant to your
class, you will benefit from easier maintenance and
better execution speed by sticking with C++ virtual
functions.


I hope this helps,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com


  #3  
Old July 22nd, 2005, 09:53 PM
David White
Guest
 
Posts: n/a
Default Re: How many virtual functions before needing dispatch tables?

"The Stevemeister" <none@none.com> wrote in message
news:WSGld.18319$xB1.16975@fe33.usenetserver.com.. .[color=blue]
> Hi, I have an entity class (from a rendering engine)
> with about 100 functions now that are virtual. So far
> no slowdowns,[/color]

I wouldn't expect a slowdown no matter how many virtual functions you have,
for the same reason that I wouldn't expect the time to access a specific
element of an array to increase if you make the array larger. For most CPUs
a virtual function call is just a couple of indirect memory accesses at
constant offsets and then an indirect call.
[color=blue]
> but since I've done alot of work with
> OWL and MFC over the years, and I know that when the
> virtual functions get too many, OWL and MFC result
> to dispatch tables.[/color]

That's not because the number of virtual functions would cause any slowing.
There are probably a number of reasons they chose such a system, but one is
that you don't know what messages need to be despatched until run-time,
since users can define their own messages, whereas virtual functions need to
be known at compile time.

DW



  #4  
Old July 22nd, 2005, 09:53 PM
The Stevemeister
Guest
 
Posts: n/a
Default Re: How many virtual functions before needing dispatch tables?

Oh I see... makes perfect sense now. Thanks alot
for the information guys.
Steve

--------------------
Steven E.
www.rick-n-steve.com

  #5  
Old July 22nd, 2005, 09:54 PM
Mike Smith
Guest
 
Posts: n/a
Default Re: How many virtual functions before needing dispatch tables?

The Stevemeister wrote:
[color=blue]
> Hi, I have an entity class (from a rendering engine)
> with about 100 functions now that are virtual. So far
> no slowdowns, but since I've done alot of work with
> OWL and MFC over the years, and I know that when the
> virtual functions get too many, OWL and MFC result
> to dispatch tables.
>
> Question is, at what point do I say, "At what point
> do I switch to dispatch tables?"[/color]

IIRC the use of dispatch tables is not due to the *number* of functions,
but rather they are used to provide the mapping between Windows messages
and virtual functions to handle those messages. Needless to say, there
are *lots* of Windows messages that a given GUI widget might need to
handle...

--
Mike Smith
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.