dtable->class

Alexandre Oliva oliva at dcc.unicamp.br
Mon May 26 03:05:44 PDT 1997


tullmann  writes:

> I've been browsing the Kaffe sources and I have a simple question for
> anyone: Why is the class of an object stored in its dispatch table?
> And, not, as I would expect, in the object itself?

If an object pointed to both its class and its dispatch table, you'd
be wasting a pointer per object.  If the object pointed only to its
class, you'd have two levels of indirection to obtain the dispatch
table.  Since a lookup in the dispatch table is probably the commonest
operation on an object, it deserves a speed optimization, so an object
may store a pointer to the dispatch table.  Since there's a single
dispatch table for every class, it may point to the class in case one
needs a pointer to the actual class, so that you don't have to store
the pointer to the class in the object itself.

-- 
Alexandre Oliva
mailto:oliva at dcc.unicamp.br mailto:aoliva at acm.org
Universidade Estadual de Campinas, SP, Brasil


More information about the kaffe mailing list