[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] idea of how to implement a weak array

At 2:07 Uhr +0100 05.03.2006, stefan kersten wrote:
On Sun, Mar 05, 2006 at 12:51:13AM +0100, Julian Rohrhuber wrote:
 An array that has been marked weak should behave as if it could not
 contain pointers (i.e. it is not scanned any further by marking it

 This would fail in the (improbable?) case that an equal object is
 stored at the same memory address again.

nice idea, but there appears to be a problem: memory isn't
necessarily reused directly after finishing a collection, so
the weak array may point to an `object' that is still equal
to the copy but contains dangling pointers.

yes, this is true.

another proposal: a WeakArray points to instances of
WeakPointer, which store a reference to the array, their
index and the actual data. when the WeakPointer is finalized
(at the beginning of a flip), it nils the corresponding slot
of its WeakArray in the finalizer func. the downside is that
you have to deal with WeakPointers explicitly and not keep
references to the data they point to.

and another one: keep a weak identity dictionary at a
special global location; before a flip, scan the white list
for objects contained in the weak dict and nil any slots
found. the downside is that flips are not in O(1) anymore
(they aren't anyway with finalizers).

this would be a nice feature. No need for dependency releasing, due to the fast access to the reference object any object can do that independently.