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:
“What is man in nature? A nothing in comparison with the infinite, an all in comparison with the nothinga mean between nothing and everything.”
—Blaise Pascal (16231662)
“From top to bottom of the ladder, greed is aroused without knowing where to find ultimate foothold. Nothing can calm it, since its goal is far beyond all it can attain. Reality seems valueless by comparison with the dreams of fevered imaginations; reality is therefore abandoned.”
—Emile Durkheim (18581917)
“The last alternatives they face
Of face, without the life to save,
Being from all salvation weaned
A stag charged both at heel and head:
Who would come back is turned a fiend
Instructed by the fiery dead.”
—Allen Tate (18991979)