Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2007-03-06 10:58:13


gast128 wrote:
> Robert Ramey <ramey <at> rrsd.com> writes:
>
>>
>> I don't see any problem with the code snippet. Maybe you want
>> to make small test which we run here.
>
> ok here it comes. It looks artificial, but it is just a
> simplification of a case. It gives an access violation after thhe
> load, when it tries to destroy the object.
>

OK - here are the changes I made in order for your example to work:

the main one is to enclose the output in {} to be sure that the xml
archive dtor is called. The ensures that the xml file contains the
trailer tags. This was what calling the load exception. I discovered
this by visually inspecting the xml file to and it was obvious to see
that it wasn't terminated correctly.

I just commented out some stuff that made no sense to me.

Robert Ramey

int main()
{
BoostExample obj;
std::stringstream sstr;
//save make sure dtor is called on the oa
// by enclosing it in {}
{
boost::archive::xml_oarchive oa(sstr);
oa << BOOST_SERIALIZATION_NVP(obj);
}
//triggers a load exception
// what is this for?
#if 0
std::string str = sstr.str();
boost::replace_all(str, "<m_ptr1>", "<m_ptr1");
sstr.str(str);
//load
obj.m_ptr.reset();
obj.m_ptr1.reset();
sstr.seekg(0);
#endif
//load
try
{
boost::archive::xml_iarchive ia(sstr);
try
{
ia >> BOOST_SERIALIZATION_NVP(obj);
}
catch (boost::archive::archive_exception& /*re*/)
{
ia.delete_created_pointers();
}
}
catch (boost::archive::archive_exception& /*re*/)
{
}
}


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