15 May 19:31
Re: in-memory stream, binary archive,serialization
From: Matthias Troyer <troyer <at> phys.ethz.ch>
Subject: Re: in-memory stream, binary archive,serialization
Newsgroups: gmane.comp.lib.boost.user
Date: 2008-05-15 17:31:30 GMT
Subject: Re: in-memory stream, binary archive,serialization
Newsgroups: gmane.comp.lib.boost.user
Date: 2008-05-15 17:31:30 GMT
On 14 May 2008, at 22:17, Victor Whiskey Yankee wrote:
Could you just post it to the list?
Here is an example program:
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/iostreams/stream_buffer.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/device/back_inserter.hpp>
#include <boost/serialization/vector.hpp>
#include <vector>
#include <iostream>
int main()
{
namespace io = boost::iostreams;
typedef std::vector<char> buffer_type;
buffer_type buffer;
const std::vector<double> data(10000000);
io::stream<io::back_insert_device<buffer_type> > output_stream(buffer);
boost::archive::binary_oarchive oa(output_stream);
oa << data;
output_stream.flush();
std::vector<double> data_in;
io::basic_array_source<char> source(&buffer[0],buffer.size());
io::stream<io::basic_array_source <char> > input_stream(source);
boost::archive::binary_iarchive ia(input_stream);
ia >> data_in;
}
_______________________________________________ Boost-users mailing list Boost-users <at> lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
RSS Feed