Next: , Up: VCL Miscellanea

8.4.1 Object system implementation

The object system is implemented in the vcl/object.c and vcl/object.h files. Every interface is identified with an integer, which is also an index to the vcl_ifaces growing array of interface descriptors (struct vcl_iface_dsc). Every virtual method (generic, not an actual implementation) is identified with an integer from one to (method_counter - 1). Methods of one interface are assigned consecutive integer values (items first_fn and fn_count in struct vcl_iface_dsc).

A class is identified with vcl_vtable, which is an array (of length method_counter), in the zero slot there is a pointer struct vcl_class_dsc, in the next slots there are pointers to implementations of virtual functions. The check whether a given class supports a given interface is implemented by a check whether the appropriate slot for first_fn of that interface is non-empty. All interfaces must be defined before the first class definition, because otherwise different classes would have different sizes of vtables and a check whether a new interface is supported by the old class could cause invalid memory access.