Boost logo

Boost Users :

Subject: [Boost-users] serialization deserialization through the pointer
From: niranjan bangera (niranjannina_at_[hidden])
Date: 2009-01-30 03:52:45


hi all,

    i am facing some problem in my code. Please help me to tackle it.

BOOST Version : 1.36.0
compliler : gnu-gcc-/4.1.1-binutils-2.16.1/x86_64-pc-linux2.4/bin/gcc

example of my prog:

header:

my.h

----
class my
{
    int var1;
    int var2;
    structure object; // structure is the some other structure which is
defined(i have defied the serialization function for this also...
/*serialization function*/
    friend class boost::serialization::access;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int file_version)
    {
        ar & var1;
        ar & var2;
        ar & object;
    }
};
mymain.cpp
----------
#include "boost/archive/text_iarchive.hpp"
#include "boost/archive/text_oarchive.hpp"
#include "boost/serialization/access.hpp"
#include "boost/serialization/serialization.hpp"
#include "boost/serialization/collection_traits.hpp"
#include "boost/serialization/utility.hpp"
#include "my.h"
class mymain
{
protected:
      my * ptr;
public:
void mytake_arch();
void myretrive_arch();
};
void mymain::mytake_arch()
{
std::ofstream  ofs("filename");
        {
            boost::archive::text_oarchive oa(ofs);
            oa << ptr;
        }
}
void mymain::myretrive_arch()
{
            mymain *ptr = NULL; //// Confused in this, This is correct or
wrong, if wront what else i can use
            std::ifstream ifs("filename");
            boost::archive::text_iarchive ia(ifs);
            ia >> ptr;
}
int main()
{
mymain obj;
obj.mytake_arch();
obj.myretrive_arch();
}
Problem:
-------
    I have some confusion in retriving, Whether the way in which i retrieved
is correct or wrong. Any other replacement or modification can be done for
the retriving part(myretrive_arch() function). Please let me know. because
the retrived ptr(pointer retrived) causes segmentation fault whenenver i use
it for some other application.
Any suggestions will be apprciated.
Thanks,
Niranjan


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net