Number of references to a Class Object
spir
denis.spir at gmail.com
Mon Feb 14 09:29:14 PST 2011
On 02/14/2011 03:34 PM, Stanislav Blinov wrote:
> 12.02.2011 18:44, d coder пишет:
>>> Also tango (for D 1.0) implements it.
>>> Link:
>>> http://www.dsource.org/projects/tango/docs/current/tango.core.WeakRef.html
>>>
>>> Might be worth a look if you are going to implement it for D 2.0.
>>>
>> I looked at the D1 implementation. It depends on GC methods
>> weakPointerCreate and weakPointerDestroy. These functions are
>> implemented in D1 GC as extern C functions.
>>
>> It seems most of this code should be directly portable to D2, it would
>> certainly require changes in the DMD2 source code. I have never worked
>> at that level and have used D2 only for past couple of months. While I
>> can give that a blind try, it would be useful only if it gets
>> excepted in DMD2.
>>
>> What do you guys suggest?
>>
> I remember reading a discussion about weak references some time ago. You
> *could* implement them using functions rt_attachDisposeEvent and
> rt_detachDisposeEvent, which are extern(C) and declared in object.d (actually,
> object_.d of dmd's druntime source), and AFAIR Tango uses something similar.
>
> Normally, a (hypothetical) WeakRef would nullify the non-GC-scanned reference
> in a dispose handler. But there is an issue with this, as dispose handlers are
> run *after* the GC resumes all threads, which means that it is still possible
> that a WeakRef implementation would supply the client code a presumably valid
> reference just before some thread deletes/clears it - a straight way to
> AV/segfault. Of course, this is no problem for single-threaded applications,
> but then again, weak references are not that useful in such apps as their
> usefulness manifests almost entirely in concurrent code.
People interested in weakref implementation may have a look at Lua. Because
it's in plain standard C99 and lightweight. (but the code is not very beautiful
imo and has very few comments)
Denis
--
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d-learn
mailing list