Set restoreFromSnapshot: - why additional snapshotCopy?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Set restoreFromSnapshot: - why additional snapshotCopy?

Andreas Tönne
Set restoreFromSnapshot: - why additional snapshotCopy? Lukas and others,

this is a question mainly out of curiousity, but also something I like to suggest for future documentation.

I stumbled across the snapshotCopy / restoreFromSnapshot: pair of methods of class Set. What puzzles me is that restoreFromSnapshot: needs to do an additional snapshotCopy of the stored object. So each Set is snapshot-copied at least twice if put in the state.

I had assumed that making a snapshotCopy initially when the Set is put in the snapshot (register:) should be enough but I learned with a similar implementation for Bag that this results in aliasing errors (a modified Bag is restored when reverting to an older continuation).

Why does one need to copy twice?

Andreas
--
Andreas Tönne
Lead Consultant
Cincom Systems GmbH & Co. oHG
Tel.: +49 6196 9003 100
Mobile: +49 172 6159272
Fax: +49 6196 9003 270



Geschäftsführer/Managing Directors: Thomas M. Nies, Gerald L. Shawhan
oHG mit Sitz/based in Schwalbach/Ts. (Amtsgericht Königstein/Ts. HRA 2653)
Pers. haftender Gesellschafter/Partner liable to unlimited extent:
Cincom Systems Verwaltungsgesellschaft mbH (Amtsgericht Königstein/Ts. HRB 5069)


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Set restoreFromSnapshot: - why additional snapshotCopy?

Lukas Renggli
>  I stumbled across the snapshotCopy / restoreFromSnapshot: pair of methods
> of class Set. What puzzles me is that restoreFromSnapshot: needs to do an
> additional snapshotCopy of the stored object. So each Set is snapshot-copied
> at least twice if put in the state.

The internal implementation of Collections differ heavily in Smalltalk
dialects. For example the Set in Squeak is implemented as a container
object that references an array of elements. In VisualWorks the Set is
an indexable object itself.

In Squeak we need to make sure that both objects - the set container
and the array - are properly copied. That's why the set is copied
first before restoring into the existing object. The tests extensively
cover this fact.

Because of these differences between the platforms all the
#snapshotCopy and #restoreFromSnapshot: code is in the platform
dependent code. Obviously the porters to VisualWorks just took the
Squeak code, even if that code would not be necessary in this case. It
doesn't hurt either, though.

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside