Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] Is this example legal usage of the serialization library
From: elizabeta petreska (elizabeta.petreska_at_[hidden])
Date: 2010-08-26 14:14:31


Hi ,

Thanks for the explanation, and for the great library.

I never thought about that, that the pointer may be referenced by other
objects, or maybe refering to some derived object.

Here is why I want to do that :
I have project saving/loading feature implemented with boost serialization
library. As part of my project saving , I need to save state for the dockbar
controls too ( things like are buttons enabled or disabled).
But because the saving and loading is on different thread I just can't say :

ar<< dockBarPtr;

because than the serialization library will create my dockbar widget in
thread other than the main thread which is error.

So far I am doing this and everything works fine, but I was afraid that am
doing something prone to error, which is true, as I suspect . I guess it is
time to rethink this

On Thu, Aug 26, 2010 at 8:52 PM, Robert Ramey <ramey_at_[hidden]> wrote:

> Elizabeta wrote:
> > Hi,
> >
> > Is it ok to serialize/deserialize in the object I get when
> > dereference a pointer ?
> >
> > void f()
> > {
> >
> > B* bObj=new B();
> >
> > /// save
> > {
> > std::ofstream ofs("C:\\hh.txt");
> > boost::archive::xml_oarchive oa(ofs);
> > oa & make_nvp("bObj",*bObj);
> > }
> > //// Load
> > {
> > std::ifstream ifs("C:\\hh.txt");
> >
> > boost::archive::xml_iarchive ia(ifs);
> > ia & make_nvp("bObj",*bObj);
> > }
> > }
> >
> > My second question :
> > Is it ok to serialize/deserialize in *this ?
> >
> > Thanks
>
> I'm going to rephrase the question for my own convenience:
>
> "How is the serialization library intended to be used to do the equivalent
> of: stream << *x ?"
>
> Here is my answer to my own question.
>
> Serializing a data object in a way that most people intend requires that
> the
> object recreated be "equivalent or substitutable" for the original object.
> When an object includes a pointer, it becomes clear that this is not so
> easy. There are a number of issues the crop up - including
>
> a) the fact that pointer to class X might really be refering to some
> derived
> class (virtual inheritance)
> b) there might be multiple pointers refering to the same object.
> c) same problems for references
> d) an the fact that all this might be going on simultaneously.
>
> The usage of ar << *x or ar << *this is an indication that the user is
> likely to "re-implement" some of the serialization library. This might
> occur because the simple interface of the library suggests that it doesn't
> do much and this is not at all true. Sooooo if you find yourself wanting
> to
> do this, step back and think about why you want to do this. Look into the
> library documentation and examples to see how you might get what you want
> without doing this. If it's still not clear, it's likely that your
> overlooking something that the library does that is not obvious. If you
> still feel you have to do this, I've failed in my task.
>
> So the short answer to my phrasing of your question is:
>
> "How is the serialization library intended to be used to do the equivalent
> of: stream << *x ?"
>
> ar << x
>
> This DOES do ar << *x plus everything else that has to be done to make such
> an operation make any sense at all.
>
> Robert Ramey
>
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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