WeakRefs for a CPP->D wrapper

Tobias Pankrath tobias at pankrath.net
Sat Jan 11 12:17:12 PST 2014


> Object[void*] wrappingRegistry;
>
> but of course that prevents the wrapped objects from being 
> garbage collected - I need weak ref semantics.
>
> I had a go at making it e.g.
> ulong[ulong] and storing the cast(ulong) address of the D 
> object, but it seems that I don't understand what taking the 
> address of an obj (&obj) actually is doing - it doesn't seem to 
> point to the memory occupied by the object but instead to the 
> address of the variable pointing to the object?
>

class X {};
X x;

x is an reference to an instance of X, with other words a pointer 
without arithmetic but with syntax sugar. &x will take the 
address of this pointer/reference. If you want the address of the 
actual instance, you can use cast(void*) for example.


More information about the Digitalmars-d-learn mailing list