Comparison With Alternatives
The vtable is generally a good performance trade-off to achieve dynamic dispatch, but there are alternatives, such as binary tree dispatch, with higher performance but different costs.
However, vtables only allow for single dispatch on the special "this" parameter, in contrast to multiple dispatch (as in CLOS or Dylan), where the types of all parameters can be taken into account in dispatching.
Vtables also only work if dispatching is constrained to a known set of methods, so they can be placed in a simple array built at compile time, in contrast to duck typing languages (such as Smalltalk, Python or JavaScript).
Languages that provide either or both of these features often dispatch by looking up a string in a hash table, or some other equivalent method. There are a variety of tricks to speed this up (e.g., interning/tokenizing method names, caching lookups, just-in-time compilation), and dispatch time often does not have a significant effect on total processing time, but nonetheless, vtable lookup is obviously faster. Vtables are also simpler to implement and debug, and closer to the "C style" than hash tables of strings.
Note that Objective-C 2.1 now supports vtable dispatch under 64-bit Mac OS X 10.6+.
Read more about this topic: Virtual Method Table
Famous quotes containing the words comparison with, comparison and/or alternatives:
“Certainly there is not the fight recorded in Concord history, at least, if in the history of America, that will bear a moments comparison with this, whether for the numbers engaged in it, or for the patriotism and heroism displayed.”
—Henry David Thoreau (18171862)
“The difference between human vision and the image perceived by the faceted eye of an insect may be compared with the difference between a half-tone block made with the very finest screen and the corresponding picture as represented by the very coarse screening used in common newspaper pictorial reproduction. The same comparison holds good between the way Gogol saw things and the way average readers and average writers see things.”
—Vladimir Nabokov (18991977)
“Clearly, society has a tremendous stake in insisting on a womans natural fitness for the career of mother: the alternatives are all too expensive.”
—Ann Oakley (b. 1944)