WeakRefs for a CPP->D wrapper
Abdulhaq
alynch4047 at gmail.com
Sun Jan 12 03:15:47 PST 2014
On Sunday, 12 January 2014 at 10:48:15 UTC, Abdulhaq wrote:
>>
>> No, try this:
>> import std.stdio;
>> class X {}
>> void foo(X x) { writeln(cast(void*) x); }
>>
>> void main() {
>> X x; // null reference by default.
>> writeln(cast(void*) x);
>> foo(x);
>>
>> x = new X;
>> writeln(cast(void*) x);
>> foo(x);
>> }
>
> Thanks Tobias that indeed works, unfortunately storing the
> address as ulong in an AA does not seem to be defeating the
> garbage collector!
>
> I guess I'll have to go for a WeakRef implementation, I'll try
> Robert's implementation in signals, but I'd really like to know
> how long it is likely to last as a working weak ref (in terms
> of the D GC changing etc.) and if I'm taking the right approach.
Sorry to reply to my own message, looking at Robert's
InvisibleAddress class I think he's hiding the address from the
GC by e.g. rotating the bits in the ulong. He's also made it all
thread safe - I certainly don't understand the details but it's
given me some ideas.
More information about the Digitalmars-d-learn
mailing list