|
Boost Users : |
Subject: Re: [Boost-users] Performance of boost::serialization
From: Robert Ramey (ramey_at_[hidden])
Date: 2010-09-18 12:43:05
Daniel Herb wrote:
> Thanks for the answers!
> I've tested some other cases based on your suggestions and now have
> the following situation:
> - I create package classes which are derived from base classes, these
> will hold non-pointer objects
> - The packages split the objects into categories
> - On the lowest level I have a list of shared_ptr<Package> - That way
> I still have some kind of dynamic without wasting to much performance
>
> I guess that's at least somehow what Robert suggested. The problem I
> have with this is the following:
> My application uses shared_ptr to hold most of the data. So if i want
> to create a package I would have to copy the data first before I can
> put it into the container within the package.
> Am I right or have I missed some part of the idea?
I think you've got it. As you can see, it's basically a way to use
the right subset of serialization functionality. To refine the idea,
I thought about this a tiny bit more and here would be another
thing to try. I don't remember if its the same as I suggested before
struct my_data {
...
shared_ptr<T1> m_t1;
...
template<class Archive>
void serialization(... // the normal way
};
// this makes sure that new values are resent each time
BOOST_SERIALIZATION_TRACKING(T1, no_tracking)
...
struct my_tranmission_wrapper {
// don't put any pointers here !!!
const T1 & m_t1;
...
my_transmission_wrapper(my_data &d) :
m_t1(d.m_t1),
...
{}
}
sender
binary_ostream_buf bs; // created connection to other machine
binary_oarchive boa(bs)
my_transmission_wrapper tw(d);
my_data d;
boa << d; // first transmission creates all the shared pointers
at the other end of the system
loop{
// update d with new values even though archive is not re-created
boa << tw(d); // serialize again with the new values
}
}
reciever
binary_istream_buf bs; // created connection to other machine
binary_iarchive bia(bs);
my_data d;
bia >> d; // first transmission creates all the shared pointers
at the other end of the system
my_transmission_wrapper tw(d);
loop{
bia >> tw(d); // serialize again with the new values
// update d with new values even though archive is not re-created
// d has new values
do_work(&d);
}
Good luck with this
Robert Ramey
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