I'm implementing a wrapper program for wrapping generic C++
libraries - it's going very well (subclassing, virtual methods,
nested classes, enums working) but I've hit an area that I don't
have enough D experience to answer, and am hoping someone can
point me in the right direction. My background is lots of
professional Java, Python etc., but not so much writing of C++
(plenty of reading but not writing).
I need to maintain a mapping between C++ void* addresses and D
wrapper Objects. The naive implementation would be
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?
I've had a good google around and because my understanding is
poor in this area (GC innards, shared data, D pointers etc) I
can't identify which of the implementations around is best for
2.064/2.065 and moving forwards. My best guess is the WeakRef
found in this one:
https://github.com/phobos-x/phobosx/blob/master/source/phobosx/signal.d
by Robert in his signals2 implementation. Can anyone expain what
is going on in WeakRef and InvisibleAddress?
thanks for any help you can give me.