Double Dispatch - A Common Idiom

A Common Idiom

The common idiom in the examples presented above, is that the selection of the appropriate algorithm is based on the call's argument types at runtime. The call is therefore subject to all the usual additional performance costs that are associated with dynamic resolution of calls, usually more than in a language supporting only single method dispatch. In C++, for example, a dynamic function call is usually resolved by a single offset calculation - which is possible because the compiler knows the location of the function in the object's method table and so can statically calculate the offset. In a language supporting double dispatch, this is slightly more costly, because the compiler must generate code to calculate the method's offset in the method table at runtime, thereby increasing the overall instruction path length (by an amount that is likely to be no more than the total number of calls to the function, which may not be very significant).

Read more about this topic:  Double Dispatch

Famous quotes containing the words common and/or idiom:

    It is a very common error of some unscrupulously infidel-minded, selfish, unprincipled, or downright knavish men, to suppose that believing men, or benevolent-hearted men, or good men, do not know enough to be unscrupulously selfish, do not know enough to be unscrupulous knaves.
    Herman Melville (1819–1891)

    I have developed a visionary modern lyric, and, for it, an idiom in which I can write lyrically, colloquially, and dramatically. My subject is city life—with its sofas, hotel corridors, cinemas, underworlds, cardboard suitcases, self-willed buses, banknotes, soapy bathrooms, newspaper-filled parks; and its anguish, its enraged excitement, its great lonely joys.
    Rosemary Tonks (b. 1932)