WeakRefs for a CPP->D wrapper

Abdulhaq alynch4047 at gmail.com
Sun Jan 12 04:14:37 PST 2014


On Sunday, 12 January 2014 at 12:12:53 UTC, Tobias Pankrath wrote:
> 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.
>
> The current GC is imprecise. Everything that looks like a 
> pointer at the bit level, is treated like one. I can't help you 
> create weak references.

No don't worry you've got me past that point of incomprehension, 
thanks again



More information about the Digitalmars-d-learn mailing list