
On Friday 24 June 2005 12:27, Joaquín Mª López Muñoz wrote:
The new rule introduced in Boost.Serialization that forbids saving of non-const objects has proved a little controversial. My point of view is that the rule, albeit far from perfect, provides some level of safety against hard to track errors. Others' opinions differ.
The current rule is a rough approximation to what IMHO would constitute the right enforcement: everytime a trackable object is saved, check wether an object with the same address has been previously saved and, if so, make sure that the object didn't change.
To avoid getting deep in "what's trackable object" discussion, we can reformulate that as "everytime serialization is about to skip writing of object's data and write id of previously saved object, check.......".
The hardest part is checking for equality. My proposal is to follow a hash-based approach, which is effective both in terms of complexity and space (one word per tracked object.), and does not impose any special requirement on the serialized objects (for instance, an approach based on operator== would require that objects be equalitycomparable).
.....
This implementation does not impose any additional requirement on the objects being serialized and is totally transparent to the user (she doesn't have to do any hash-related work herself.) With the computed hash values, Boost.Serialization can emmit run-time errors if a trackable object is serialized twice and changed in between (currently, the errors are compile-time.)
What do you think?
This suggestion is very interesting! But I wonder, how you can detect for sure that objects are the same using a hash. Two different object can hash to the same value? Maybe, operator== is still needed? - Volodya