|
Boost Users : |
From: cpper (coolcute_at_[hidden])
Date: 2008-04-23 08:40:08
Hi all:
I have spent a day long in finding a way of
combining serialization archive with iostreams filtering_streambuf
but now I encounter a strange problem,
here is my code:
#include <sstream>
#include <boost/iostreams/device/back_inserter.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/string.hpp>
#include <boost/iostreams/stream.hpp>
#include <vector>
int main ()
{
std::vector<char> store;
boost::iostreams::filtering_ostreambuf out;
out.push(boost::iostreams::bzip2_compressor());
out.push(boost::iostreams::back_inserter(store));
{
boost::archive::binary_oarchive oa(out);
oa << "abc";
// archive closed when destructors are called
//out.pop ();//call before oa destroyed, crashed!!!!
}
out.pop ();//call after oa destroyed the behavior seems normal
//out.reset ();
boost::iostreams::filtering_istreambuf in;
in.push(boost::iostreams::bzip2_decompressor());
in.push(boost::make_iterator_range(store));
{
std::string aft;
boost::archive::binary_iarchive ia(in);
ia >> aft;
}
}
if I call pop() or reset() before archive destructor called.
exception in:
C:\Program Files\Microsoft Visual Studio 9.0\VC\crt\src\streambuf
in this member method of std::streambuf
int pubsync()
error message is below:
Unhandled exception at 0x10499231 (msvcp90d.dll) in basic_usage.exe:
0xC0000005: Access violation reading location 0xfeeeff1e.
If I call out.pop() after oa destroyed,the behavior is exactly what I want.
But I just wonder why it goes in this way?
Code like below
{
boost::archive::binary_oarchive oa(out);
oa << "abc";
}
out.pop ();//call after oa destroyed the behavior seems normal
which appears that I have done something wrong...
I'm using VS2008TS under Win2003SP2
Can anybody help?
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