Remix.run Logo
akoboldfrying 3 hours ago

> using the vtable as a hash table instead of a list.

Could you explain this a bit more? The word "list" makes me think you might be thinking that virtual method lookup iterates over each element of the vtable, doing comparisons until it finds a match -- but I'm certain that this is not how virtual method invocation works in C++. The vtable is constructed at compile time and is already the simplest possible "perfect hashtable": a short, dense array with each virtual method mapping to a function pointer at a statically known index.

hinkley 2 hours ago | parent [-]

The problem they were trying to solve was multiple inheritance, and by nominal type not by code reuse. So interfaces, basically.

So these guys essentially assigned a hashcode to every function of every interface and then you would do dispatch instead of obj.vtable[12] you would do modular math x = singature.hash % len(obj.vtable) and call that.

I believe this was sometime around 2005-2008 and they found that it was fast enough on hardware of that era to be usable.