What are reasonable basic implementations of virtual or dynamic dispatch?

The most popular way (or so I heard) seems to be a virtual table, but what other alternatives exist?

This question gives some examples, such as walking through the hierarchy at runtime or comparing the addresses of objects with some larger information table, but the question is pretty C ++ although the answers are mostly not.

So, here is an agnostic language (or so I hope):

What are other ways to implement virtual / dynamic dispatch besides vtables?

Please note that this is not a compromise between speed, ease of implementation, code size, etc., although the answers would be very nice.

+5
source share
2 answers

Method 1: Flat VTable. All virtual methods of the class type (including inherited methods) are presented in the table of method pointers, one for each virtual method. The call requires an indirect call to the method pointer with a fixed offset in the table. Each new class creates its own vtable, copies the vtable of its ancestor, overwrites pointers to virtual methods that override the class, with pointers to new methods, and adds new virtual methods defined in the class at the end of the table.

2: VTable ( ) , , vtable. , id method . Invocation , . , .. , .

3: . . , . case/switch . .

vtables . , . Windows WndProc - , wndproc - . WndProc , .

- , . VTable ( ), . VTable , VTables , , .

Delphi VTables, , WndProcs .

+8

, Python : , , -, . , - . .

0

All Articles