Boost logo

Boost Users :

From: Dominick Layfield (dom.layfield_at_[hidden])
Date: 2007-08-18 13:14:17


Frank Birbacher wrote:
> I now noticed that the link I posted does not reference excatly what I
> meant to point at. Your code makes me think that you have not read what
> I wanted you to read. Here it goes.
>
> READ THIS:
>
> http://www.boost.org/libs/serialization/doc/rationale.html#trap

Well, Hector may not have read this, but I did! And it seems that I have the
same problem as him. If I make the object I want to serialize a const, the
(completely incomprehensible) compile error goes away. Any chance this could be
added to a boost::serialization FAQ?

It appears that I have a choice between (i) doing a const_cast on every object I
want to save, and (ii) inserting a BOOST_CLASS_TRACKING(XXX,
boost::serialization::track_never) line into my source code. Both are ugly, and
although the former might be safe, it certainly looks dangerous!

The "Compile time trap" section of the documentation doesn't actually explain
what "object tracking" is all about. Neither (amusingly) does the
Boost->Serialization->Reference->Special Considerations->Object Tracking section!

After re-reading these sections several times, I realized that this is all
related to serializing pointers. To my mind, it is not at all intuitive what
should happen if I try to serialize a pointer to an object.

What Boost::serialization seems to do is to serialize the object itself, but
wrapped up in some magic that remembers the object was output/input through a
pointer. i.e. if I create a my_class object, then output a pointer to the
object, the object itself is output, and when I come to input the pointer, the
library silently creates an object of type my_class, then puts a pointer to the
object into my pointer. Is that about right?

If so, this is (1) not transparent, and (2) seems ludicrously complex. As
alluded to in the documentation, this creates a morass of problems
(object-tracking, memory leaks etc.). Having said that, I have to applaud the
tour-de-force of C++ wizardry required to make all of this magic work.

To quote Bjarne Stroustrup, "...but you have to be very clever. If any of you
have seen some of the Boost stuff, you don't want to be that clever!" (from his
recent Waterloo talk)

It seems to me that a cleaner, simpler (and less ambitious) solution would just
be to make serialization of pointers an error. What on earth does it actually
mean to serialize a pointer? And why would I want to do such a thing, anyway?

-- Dominick


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net