Re: New Implementation of Virtual Functions in C++

Matthias Neeracher <neeri@iis.ee.ethz.ch>
19 Nov 1999 22:34:13 -0500

          From comp.compilers

Related articles
New Implementation of Virtual Functions in C++ sjmccaug@prairienet.org (1999-11-18)
Re: New Implementation of Virtual Functions in C++ johnmce@texas.net (1999-11-19)
Re: New Implementation of Virtual Functions in C++ neeri@iis.ee.ethz.ch (Matthias Neeracher) (1999-11-19)
Re: New Implementation of Virtual Functions in C++ landauer@apple.com (1999-11-19)
Re: New Implementation of Virtual Functions in C++ jsgray@acm.org (Jan Gray) (1999-11-23)
| List of all articles for this month |

From: Matthias Neeracher <neeri@iis.ee.ethz.ch>
Newsgroups: comp.compilers
Date: 19 Nov 1999 22:34:13 -0500
Organization: Integrated Systems Laboratory, ETH, Zurich
References: 99-11-100
Keywords: C++

sjmccaug@prairienet.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
inheritance hierarchies.


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
--
Matthias Neeracher <neeri@iis.ee.ethz.ch> http://www.iis.ee.ethz.ch/~neeri


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.