The Stevemeister said:
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