|
![](/i/fill.gif) |
> > A related misconception is that calling a virtual function is very
> > slow. Yes, it's a bit slower than calling a regular function, but
> > the speed difference is usually one or two CPU clocks, which
> > usually doesn't matter, specially if the function itself takes
> > hundreds of clocks.
>
> Of course, you assume the vtable is in the cache and the processor supports
> the necessary indirect addressing modes.
I think the most important thing to remember in connection with
virtual functions is that a "hand-crafted" solution will most probably
end up no faster, but a lot more complicated and messy.
The kind of flexibility you get from the dynamically binded functions
simply comes with a cost. Fortunately, that cost probably won't be the
one that slows the program to a crawling halt. :-)
--
Ole Laursen
http://sunsite.dk/olau/
Post a reply to this message
|
![](/i/fill.gif) |