473,379 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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

Jul 22 '05 #1
4 1741
"The Stevemeister" <no**@none.com> wrote in message
news:WS*******************@fe33.usenetserver.com.. .
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?"


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
Jul 22 '05 #2
"The Stevemeister" <no**@none.com> wrote in message
news:WS*******************@fe33.usenetserver.com.. .
Hi, I have an entity class (from a rendering engine)
with about 100 functions now that are virtual. So far
no slowdowns,
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.
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.


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

Jul 22 '05 #3
Oh I see... makes perfect sense now. Thanks alot
for the information guys.
Steve

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

Jul 22 '05 #4
The Stevemeister wrote:
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?"


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
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DaKoadMunky | last post by:
I was recently looking at some assembly code generated by my compiler. When examining the assembly code associated with constructors I noticed that the dynamic-dispatch mechanism was enabled...
25
by: Stijn Oude Brunink | last post by:
Hello, I have the following trade off to make: A base class with 2 virtual functions would be realy helpfull for the problem I'm working on. Still though the functions that my program will use...
8
by: Floogle | last post by:
how do i create a virtual == operator. I've tried the following but it's incorrect... class Interface { ... public: virtual bool operator==(const Interface& rhs)const=0;
7
by: Calum | last post by:
Hi, I have a base class called Number that has subclasses Integer and Float. I want to be able to provide a virtual operator- in the base class so that I can subtract one Integer from another...
7
by: vaividhya | last post by:
We can have virtual destructors.Why we can't have virtual constructors?
7
by: desktop | last post by:
This page: http://www.eptacom.net/pubblicazioni/pub_eng/mdisp.html start with the line: "Virtual functions allow polymorphism on a single argument". What does that exactly mean? I guess it...
10
by: =?Utf-8?B?Y2FybG0=?= | last post by:
Hello, I searched for an answer to my question and found similar posts, but none that quite addressed the issue I am trying to resolve. Essentially, it seems like I need something like a virtual...
318
by: King Raz | last post by:
The shootout site has benchmarks comparing different languages. It includes C# Mono vs Java but not C# .NET vs Java. So I went through all the benchmark on the site ... ...
5
by: sunil | last post by:
Hello, I have a class deriving from a class that provides ability to serialize/deserialize objects over the network. There are two classes Requests (sent from client to server) Response(sent from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.