|New Implementation of Virtual Functions in C++ firstname.lastname@example.org (1999-11-18)|
|Re: New Implementation of Virtual Functions in C++ email@example.com (1999-11-19)|
|Re: New Implementation of Virtual Functions in C++ firstname.lastname@example.org (Matthias Neeracher) (1999-11-19)|
|Re: New Implementation of Virtual Functions in C++ email@example.com (1999-11-19)|
|Re: New Implementation of Virtual Functions in C++ firstname.lastname@example.org (Jan Gray) (1999-11-23)|
|From:||Matthias Neeracher <email@example.com>|
|Date:||19 Nov 1999 22:34:13 -0500|
|Organization:||Integrated Systems Laboratory, ETH, Zurich|
firstname.lastname@example.org (Scott J. McCaughrin) writes:
> A colleague informs me that virtual functions are now more commonly
> implemented via thunks (instead of class vtbls). He couldn't cite a
> source for this. Can you?
Maybe he's thinking not of the functions themselves, but of the class
pointer adjustment for multiple inheritance.
In earlier (CFront based, I think) implementations of multiple
inheritance, class vtbls used two "words" per function: A pointer to
the function code and an offset for adjusting the class pointer. This
introduced a time and space disadvantage, so some vendors (I remember
Apple's MPW C++ compiler) introduced language extensions to declare
that some class would only be used as a base class in single
Newer implementations (I specifically know that Metrowerks CodeWarrior
switched to this at some point) only use a single "word", the pointer
to the function code. If the class pointer *does* need to be adjusted,
a thunk is generated.
This probably saves both space and time since in many programs, the
vast majority of virtual calls don't need to adjust the class pointer
(code is in most derived class or in a base class starting at the same
physical address as the most derived class).
Matthias Neeracher <email@example.com> http://www.iis.ee.ethz.ch/~neeri
Return to the
Search the comp.compilers archives again.