|
Boost Users : |
Subject: Re: [Boost-users] [Serialization] creating an archive fails under GCC-4.6.0
From: François Mauger (mauger_at_[hidden])
Date: 2011-04-18 00:22:42
Hi doug,
I don't kwow how to use a string (and a stringstream
as the target of serialization). I use plain std::vector<char>
as memory buffer, both for text/XML archives and binary archives.
Here are typical bits I use :
>>>
typedef std::vector<char> buffer_type;
buffer_type buffer; // the target buffer for serialization
{
buffer.reserve (1000); // ensure some minimal capacity depending of
the expected size of the archive
// Archiving is redirected to the buffer:
namespace io = boost::iostreams;
io::stream<io::back_insert_device<buffer_type> > output_stream (buffer);
boost::archive::text_oarchive oa (output_stream);
oa << my_data;
output_stream.flush ();
}
<<<
In your case, as you use
vector<string> _frames;
as a collection of frames, I recommend this:
vector<buffer_type> _frames;
{
buffer_type dummy;
_frames.push_back (dummy); // insert first a new `frame' in the collection
}
...
buffer_type & current_buffer = _frames.back (); // use the last inserted buffer from the collection
current_buffer.reserve (1000);
...
io::stream<io::back_insert_device<buffer_type> > output_stream (current_buffer);
...
That would save a copy operation in your collection.
Hope it helps.
cheers
frc
-- doug livesey a écrit : > Hi -- I have some code that runs when compiled with GCC-4.2 (on OSX > Snow Leopard), but that throws the following error with my fresh > compile of 4.6.0: > run_features(2872) malloc: *** error for object 0x100502060: > pointer being freed was not allocated > *** set a breakpoint in malloc_error_break to debug > > The line that creates this error is here, on line > 24: https://gist.github.com/923262 > (Apologies for any egregious code abuses in there, I'm just learning!) > In the debugger, it lets me step from that line to the constructor of > xml_oarchive (line 114 of xml_oarchive.hpp), and when I try to step > any further, I get this: > run_features(2885) malloc: *** error for object 0x100501b00: > pointer being freed was not allocated > *** set a breakpoint in malloc_error_break to debug > > Program received signal SIGABRT, Aborted. > 0x00007fff871a95d6 in __kill () > > Could anyone advise me on what I could do to fix this? I really want > to be working with GCC 4.6.0 and the boost serialisation libraries. > Incidentally, I reinstalled boost after I installed the latest GCC > (with homebrew), and I'd set cc, gcc, and g++ symlinks to GCC-4.6.0 > before I did that, so boost should be compiled with the latest. > Thanks very much for any & all assistance. > Doug. > ------------------------------------------------------------------------ > > _______________________________________________ > Boost-users mailing list > Boost-users_at_[hidden] > http://lists.boost.org/mailman/listinfo.cgi/boost-users -- François Mauger Groupe "Interactions Fondamentales et Nature du Neutrino" NEMO-3/SuperNEMO Collaboration LPC Caen-CNRS/IN2P3-UCBN-ENSICAEN Département de Physique -- Université de Caen Basse-Normandie Adresse/address: Laboratoire de Physique Corpusculaire de Caen (UMR 6534) ENSICAEN 6, Boulevard du Marechal Juin 14050 CAEN Cedex FRANCE Courriel/e-mail: mauger_at_[hidden] Tél./phone: 02 31 45 25 12 / (+33) 2 31 45 25 12 Fax: 02 31 45 25 49 / (+33) 2 31 45 25 49
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