Boost C++ Libraries: Ticket #6064: serialization fails with linked list of certain size https://svn.boost.org/trac10/ticket/6064 <p> Serialization of a custom-made simple linked list fails if the list is of a certain size. Seems linked to the depth of pointers comming from the root. In the provided code if the NUM_OF_NODES is set to: </p> <ul><li>1200 everything works </li><li>1300 deserialization fails with a segfault </li><li>1500 serialization fails with a segfault </li></ul><p> If the raw pointers are replaced with boost::shared_ptr the values of NUM_OF_NODES can be roughly cut in half to get the same effects. Changing the <a class="missing wiki">SerialTest</a> classes size by adding additional fields has no effect. Compiled with gcc 4.5.2 from mingw on win xp </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;vector&gt; #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/serialization/shared_ptr.hpp&gt; #include &lt;boost/serialization/vector.hpp&gt; #include &lt;boost/archive/text_oarchive.hpp&gt; #include &lt;boost/archive/text_iarchive.hpp&gt; using namespace std; class SerialTest { public: SerialTest* next; friend class boost::serialization::access; template&lt;class Archive&gt; void serialize(Archive &amp; ar, const unsigned int version) { ar &amp; next; } SerialTest() { } }; int main() { const size_t NUM_OF_NODES = 1200; SerialTest* root = new SerialTest; SerialTest* currentNode = root; for(size_t i = 0; i &lt; NUM_OF_NODES; ++i) { SerialTest* newNode = new SerialTest; currentNode-&gt;next = newNode; currentNode = newNode; } { cout&lt;&lt;"opening ser file"&lt;&lt;endl; ofstream of("test.t"); boost::archive::text_oarchive oa{of}; cout&lt;&lt;"serialization"&lt;&lt;endl; oa &lt;&lt; root; } { cout&lt;&lt;"opening deser file"&lt;&lt;endl; SerialTest* root2; ifstream ifs("test.t"); cout&lt;&lt;"deserialization"&lt;&lt;endl; boost::archive::text_iarchive ia{ifs}; ia &gt;&gt; root2; } cout&lt;&lt;"done"&lt;&lt;endl; return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6064 Trac 1.4.3 Robert Ramey Sat, 12 Nov 2011 20:42:52 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6064#comment:1 https://svn.boost.org/trac10/ticket/6064#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> This is a stack overflow due to recursion. It's not an issue with serialization library itself. It can happen with any recurrsive structure. If you wan't to do this, you'll have to either make the stack depth larger or alter your code to avoid such deep recurrsion. </p> <p> Robert Ramey </p> Ticket