Extending D to support per-class or per-instance user-defined metadata

Jean-Louis Leroy jl at leroy.nyc
Mon Dec 11 21:03:04 UTC 2017


I realize that I focused too much on the how, and not enough on 
the why.

By "metadata" I mean the data that is "just there" in any object, 
in addition to user defined fields.

An example of per-class metadata is the pointer to the the 
virtual function table. It is installed by the compiler or the 
runtime as part of object creation. It is the same for all the 
instances of the same class.

Just like virtual functions, my openmethods library uses "method 
tables" and needs a way of finding the method table relevant to 
an object depending on its class. I want the library to work with 
objects of any classes, without requiring modifications to 
existing classes. Thus, there is a need to add that information 
to any object, in an orthogonal manner. Openmethods has two ways 
of doing this (one actually hijacks the deprecated 'deallocator' 
field in ClassInfo) but could profit from the ability to plant 
pointers right inside objects.

Examples of per-object metadata could be: a reference count, a 
time stamp, an allocator, or the database an object was fetched 
from.



More information about the Digitalmars-d mailing list