Boost C++ Libraries: Ticket #2002: bugs in load_binary and save_binary on 64 bit machines https://svn.boost.org/trac10/ticket/2002 <p> I discovered that <strong>load_binary</strong> and <strong>save_binary</strong> do not work properly on 64 bit machines.<br /> I discovered the problem on CentOS 5.1, 32 and 64 bit machines, running the attached program with <em>valgrind</em>.<br /> If you don't compile it with -DBOOST_SERIALIZATION_WORK_AROUND, the program runs correctly on the 32 bit machine only.<br /> On the 64 bit machine, the program seems to terminate correctly, but, if run with <em>valgrind</em>, a lot of errors come out.<br /> This can appear as a minor bug, but, if you try to use Boost.MPI in conjunction with serialization (for example to broadcast an object of the class Mtx_Wrap ... see ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1998" title="#1998: Bugs: Possible bug in Boost.MPI on 64 bit machines (closed: duplicate)">#1998</a>), your program crashes if you run it with more than one process.<br /> I have to add that, before boost 1.35.0 were released, I used the 1.35 development version without any problem on 32 and 64 bit machines both. At the moment, I have a lot of code that uses <strong>load_binary</strong> and <strong>save_binary</strong> like it is shown in the attached code. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2002 Trac 1.4.3 MIchele De Stefano <micdestefano@…> Tue, 10 Jun 2008 07:36:42 GMT attachment set https://svn.boost.org/trac10/ticket/2002 https://svn.boost.org/trac10/ticket/2002 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">main.cpp</span> </li> </ul> <p> Small test program for the bug </p> Ticket Robert Ramey Tue, 10 Jun 2008 15:14:50 GMT owner changed https://svn.boost.org/trac10/ticket/2002#comment:1 https://svn.boost.org/trac10/ticket/2002#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Robert Ramey</span> to <span class="trac-author">Matias Capeletto</span> </li> </ul> <p> Mattias, </p> <p> Could you take a look at this please. It looks like that our basic assumption about arrays - that elements are contiguous and a multiple of the size of the element may not be holding true on a 64 bit platform. As this is intimately related to optimization for arrays maybe you know something about this. </p> <p> Robert Ramey </p> Ticket Daryle Walker Wed, 11 Jun 2008 22:56:03 GMT <link>https://svn.boost.org/trac10/ticket/2002#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2002#comment:2</guid> <description> <p> Closed the <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1998" title="#1998: Bugs: Possible bug in Boost.MPI on 64 bit machines (closed: duplicate)">preceding bug</a> in deference to this one </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Matthias Troyer</dc:creator> <pubDate>Sat, 14 Jun 2008 20:36:28 GMT</pubDate> <title>owner changed https://svn.boost.org/trac10/ticket/2002#comment:3 https://svn.boost.org/trac10/ticket/2002#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Matias Capeletto</span> to <span class="trac-author">Matthias Troyer</span> </li> </ul> <p> Robert, I guess you wanted to assign this to me and not to matias. Contiguity of arrays and vectors is guaranteed by the standard. The first thing that comes to my mind is that actually instead of using save_binary and load_binary, array wrappers should be used. save_binary and load_binary can be dangerous. I don't have CentOS but can try it on one of our 64-bit machines. </p> Ticket Matthias Troyer Sat, 14 Jun 2008 20:49:41 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2002#comment:4 https://svn.boost.org/trac10/ticket/2002#comment:4 <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 bug is in your code. You write: </p> <blockquote> <p> ar.save_binary(data,Nel*sizeof(size_t)); </p> </blockquote> <p> while data is an array of type T, which in your example is float. On 32 bit machines this works by chance since there sizeof(float)==sizeof(size_t), but on 64-bit machines a size_t is bigger than a float. This is the reason for the bug. It is much safer to just serialize using array wrappers: </p> <p> ar &lt;&lt; serialization::make_array(data,Nel) </p> <p> which gets the correct size automatically </p> <p> Matthias </p> Ticket micdestefano@… Mon, 16 Jun 2008 16:41:37 GMT <link>https://svn.boost.org/trac10/ticket/2002#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2002#comment:5</guid> <description> <p> You are right. I'm really sorry for the "false alarm". Thank you very much. </p> <p> Michele. </p> </description> <category>Ticket</category> </item> <item> <pubDate>Mon, 03 Nov 2008 14:20:34 GMT</pubDate> <title>milestone deleted https://svn.boost.org/trac10/ticket/2002#comment:6 https://svn.boost.org/trac10/ticket/2002#comment:6 <ul> <li><strong>milestone</strong> <span class="trac-field-deleted">Boost 1.35.1</span> </li> </ul> <p> Milestone Boost 1.35.1 deleted </p> Ticket