In article <e60dbedd-a21a-4542-9e56-
21b46587a...@v16g2000prc.googlegroups.com>, james.ka...@gmail.com
says...
[ ... ]
I don't think anyone actually knows, since as far as I know,
no one has actually implemented it this way. A virtual
table look-up involves two indirections---read the vptr,
then the vtbl itself; it seems pretty obvious that a hash
table implementation can't come close. It might be useful,
however, for instrumenting the code, in order to generate
various statistics, or even doing some additional error
checking on the side (although I'm not sure what).
As I said above, my comment was just a nit---it's possible
to implement polymorphism with no information about the type
in the class object itself. Conceptually, at least; it's
probably not practical.
I can think of a way that might be practical. Allocate objects
in pools of (say) one megabyte (of virtual address space)
apiece. All objects in a given pool are of the same type. A
vtable for that pool of objects is located at the beginning of
the one megabyte range, so you can get from an object to its
vtable by anding out the bottom 20 bits of the object's
address.
This could waste a little bit of address space if you had more
than one megabyte of a given type of object, but _could_ also
be somewhat faster than the usual current implementation -- it
substitutes a CPU operation (usually quite fast) for a memory
access (often a lot slower).
those.