Boost logo

Boost :

Subject: [boost] Throws exception while deserializing large no object
From: Bikas Tanti (btanti_at_[hidden])
Date: 2011-10-20 03:07:31

I'm using vs 2010 and getting memory leaks when deserializing objects with
binary archive .

#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
class ElementResultData
        friend class boost::serialization::access;
        template<class Archive>
        void serialize(Archive & ar,const unsigned int version)
                ar & m_pass;
                ar & m_fail;
                ar & m_units;
                ar & m_result_no;
                ar & m_outof_tolerance;
                ar & m_iPartNo;
                ar & m_iActualValue;
                ar & m_iMeasurement1;
                ar & m_iMeasurement2;
                ar & m_iMeasurement3;


        std::string m_pass;
        std::string m_fail;
        std::string m_units;
        std::string m_result_no;
        std::string m_outof_tolerance;
        unsigned long m_iPartNo;
        double m_iActualValue;
        double m_iMeasurement1;
        double m_iMeasurement2;
        double m_iMeasurement3;

        ElementResultData(std::string ps,std::string fl,std::string
unit,std::string rno,std::string tol,
                int n,double av,double m1,double m2, double m3) :

class CDataResultDlg
// Construction
        std::map<int, ElementResultData> m_mElemResDatafirst;
        std::map<int, ElementResultData> m_mElemResDataSecond;
        std::map<int, ElementResultData> m_mElemResultData;


#define NUM_ELEMENTS 50000 // works fine when NUM_ELEMENTS is 1

class CDataResultDlg

for(unsigned long i=0;i<NUM_ELEMENTS;i=i+2)

//Saving Data
std::ofstream ofs(&quot;ResultData&quot;);
        // save data to archive
                boost::archive::binary_oarchive oafirst(ofs,std::ios::app);
                //write instance to archive
                int no_of_map = 2;
                oafirst&lt;&lt; no_of_map;
                oafirst &lt;&lt; m_mElemResDatafirst;
                oafirst &lt;&lt; m_mElemResDataSecond;

//Loading Data
std::ifstream ifs(&quot;ResultData&quot;,std::ios::binary);
                // create and open an archive for input
                boost::archive::binary_iarchive ia(ifs);
                // read class state from archive
                int no_of_Element;
                for(int i =0;i<no_of_Element;i++)
                   ia >>m_mElemResultData; *// Out Of Memory *

Same code works fine for text_archive.I have to serialize huge amount of
data to a file .

Any help will be appreciated .

View this message in context:
Sent from the Boost - Dev mailing list archive at

Boost list run by bdawes at, gregod at, cpdaniel at, john at