Weak references.
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sun Apr 13 12:32:38 PDT 2008
"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message
news:fttn2m$2emt$1 at digitalmars.com...
> Michel Fortin wrote:
>> On 2008-04-12 17:24:44 -0400, "Jarrett Billingsley" <kb3ctd2 at yahoo.com>
>> said:
>>
>>> Is this possible at all? Am I just not using Bill's weakref properly?
>>
>> I've been using an alternate strategy in the D/Objective-C bridge for the
>> bridged object lookup table. Basically, I'm casting object references to
>> size_t (so they're no longer pointers)
>
> Yes, that's what the weak ref class does.
>
>> and mangling the pointers (so the garbage collector can't see them as
>> pointers, I think this is no longer be necessary).
>
> I agree that that's not necessary.
>
>> When the bridged object gets deleted on the D side, it removes its
>> mangled pointer from the table.
>>
>> So if your referenced object knows about its weak reference in the table,
>> you could implement it as such and don't have to worry about null
>> pointers polluting your table.
>
> Good idea. I was thinking to suggest something like that too. A WeakRef
> class is not really an optimal way to keep track of a collection of weak
> refs. In addition to null pointers polluting the table, there's also just
> the basic overhead of needing to create an extra object for each entry.
> Ideally there would be WeakArray, WeakSet, WeakHeap... etc. I think I've
> seen such things in some language. Python maybe?
Lua's tables can have weak keys, weak values, or both.
More information about the Digitalmars-d
mailing list