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

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



Reading about garbage collecting, I had an idea how a weak array could be implemented in sc. I might be totally wrong, and this is speculative.

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 black instead of grey). When the memory of an object that it points to is reused, the array will point to some weird unpredictable data. The only thing that we can be reasonably sure is that the data will be different from the original object.

Now the weak array could be encapsuled in an object that keeps a normal list of copies of all objects in the weak array. When trying to access an object, it would compare the data at the two locations and if they are not equal, return nil and remove also the copied object from the second list (which is then garbage collected).

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

--





.