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
{
private:
        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;
        }

public:

        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;

public:
        ElementResultData(){};
        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) :
       
m_pass(ps),m_fail(fl),m_units(unit),m_result_no(rno),m_outof_tolerance(tol),m_iPartNo(n),
               
m_iActualValue(av),m_iMeasurement1(m1),m_iMeasurement2(m2),m_iMeasurement3(m3)
        {}
       
};

//DataResultDlg.h
 
class CDataResultDlg
{
// Construction
public:
        std::map<int, ElementResultData> m_mElemResDatafirst;
        std::map<int, ElementResultData> m_mElemResDataSecond;
        std::map<int, ElementResultData> m_mElemResultData;
};

//DataResultDlg.cpp

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

class CDataResultDlg
{

for(unsigned long i=0;i<NUM_ELEMENTS;i=i+2)
        {
            m_mElemResDatafirst.insert(std::make_pair(i,
ElementResultData(&quot;Pass&quot;,&quot;No&quot;,
&quot;MM&quot;,&quot;PartA&quot;,&quot;O&quot;,i,1.6020,1.0400,1.320,1.1010)));
                
m_mElemResDatafirst.insert(std::make_pair(i+1,ElementResultData(&quot;Fail&quot;,&quot;Yes&quot;,&quot;MM&quot;,&quot;PartB&quot;,&quot;O&quot;,i+1,1.085,1.0004,2.320,1.1010)));
       
        }

//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;
                ia>>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: http://boost.2283326.n4.nabble.com/Throws-exception-while-deserializing-large-no-object-tp3921077p3921077.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk