Boost C++ Libraries: Ticket #6850: serialization/deserialization does not work for more than 25 objects (very strange!!!) https://svn.boost.org/trac10/ticket/6850 <p> hello I have installed boost 1.47.0 library on my system and I have a strange problem. If I try to serialize more then 25 objects, the serialization (save()) apparently works but the deserialization (load()) does not work anymore and it gives me the following error: Unhandled exception at 0x7c812afb in Boost_tests.exe: Microsoft C++ exception: boost::archive::archive_exception at memory location 0x0012e5ec.. this error is raised when the last object (say the 26th object, if the number of objects is higher then 25) is being deserialized. here is the code: </p> <pre class="wiki">#include &lt;boost/archive/binary_oarchive.hpp&gt; #include &lt;boost/archive/binary_iarchive.hpp&gt; #include &lt;boost/serialization/string.hpp&gt; #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;fstream&gt; #include &lt;vector&gt; using namespace std; #define COUNT 26 class person; vector&lt;person&gt; v; class person { public: string _name; int _age; person (string name="Liviu", int age=25):_name(name),_age(age){}; friend class boost::serialization::access; template &lt;typename Archive&gt; void serialize(Archive &amp; ar, const unsigned int version) { ar &amp; _name; ar &amp; _age; } }; void save() { ofstream file("archiv.cst"); boost::archive::binary_oarchive oa(file); for (int i=1; i&lt;=COUNT; i++) { oa&lt;&lt;person("John",i); } file.close(); }; void load() { ifstream file("archiv.cst"); boost::archive::binary_iarchive ia(file); for (int i=1; i&lt;=COUNT; i++) { person p; ia&gt;&gt;p; v.push_back(p); // cout &lt;&lt; p._name&lt;&lt;" " &lt;&lt;p._age&lt;&lt;endl; } file.close(); }; int main() { int i; cin&gt;&gt;i; while (i!=2) { if (i==0) save(); if (i==1) load(); cin&gt;&gt;i; } } </pre><p> Can you help me please? Is something wrong with the library? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6850 Trac 1.4.3 Robert Ramey Sun, 15 Jul 2012 20:29:00 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6850#comment:1 https://svn.boost.org/trac10/ticket/6850#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> the default std::vector size is some number. You're not overriding that when oyu rebuild. You might want to look into how std:vector is serialized. I believe you should let the standard code in the library do this for you. That is, you should change your code to: </p> <pre class="wiki">#include &lt;boost/archive/binary_oarchive.hpp&gt; #include &lt;boost/archive/binary_iarchive.hpp&gt; #include &lt;boost/serialization/string.hpp&gt; #include &lt;boost/serialization/vector.hpp&gt; // note:use standard vector serialization ! #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;fstream&gt; using namespace std; #define COUNT 26 class person; vector&lt;person&gt; v; class person { public: string _name; int _age; person (string name="Liviu", int age=25):_name(name),_age(age){}; friend class boost::serialization::access; template &lt;typename Archive&gt; void serialize(Archive &amp; ar, const unsigned int version) { ar &amp; _name; ar &amp; _age; } }; void save() { ofstream file("archiv.cst"); boost::archive::binary_oarchive oa(file); oa &lt;&lt; v; file.close(); }; void load() { ifstream file("archiv.cst"); boost::archive::binary_iarchive ia(file); ia &gt;&gt; v; file.close(); }; int main() { int i; for (i=1; i&lt;=COUNT; i++){ v.push_back(person("John", i)); } cin&gt;&gt;i; while (i!=2) { if (i==0) save(); if (i==1) load(); cin&gt;&gt;i; } } </pre><p> and see how that works. I think I'm correct, so I'm going to close this item for now. </p> <p> Robert Ramey </p> Ticket