I am trying to serialize (save) and deserialize (reload) an object using Boost library in order to minimize overhead memory requirements since I created several objects. I am new to Boost library but so far I do not wish to modify the libraries I am using. I tried writing the code below but I got an error {error C2039: 'serialize' : is not a member of 'DirectedGraphicalModels::CGraph'E:\external\boost\boost_1_54_0\boost\serialization\access.hpp 118}. The header of the Graph library I am using is here
int main(int argc, char *argv[])
{
CImageGraph *pGraph = new CGraph(nStates);
cout << "Building the Graph..." << endl;
pGraph->buildImageGraphN4(fv.rows, fv.cols, pEdgeTrainer != NULL, true);
// Save data
{
const char* fileName = "Graph.txt";
// Create an output archive
std::ofstream ofs(fileName);
boost::archive::text_oarchive ar(ofs);
// Save only the pointer. This will trigger serialization
// of the object it points too, i.e., o1.
ar & pGraph;
}
// Restore data
CImageGraph *pRGraph = new CGraph(nStates);
cout << "Building the Graph for restore..." << endl;
pRGraph->buildImageGraphN4(fv.rows, fv.cols, pEdgeTrainer != NULL, true);
pRGraph;
{
const char* fileName = "Graph.txt";
// Create and input archive
std::ifstream ifs(fileName);
boost::archive::text_iarchive ar(ifs);
// Load
ar & pRGraph;
}
// Make sure we read exactly what we saved.
assert(pRGraph != pRGraph);
//assert(*pRGraph == pRGraph);
}
Kindly advice me on how I can go ahead and save and reload the Graph for further processing. So far I have referred to this articles 1 and 2 but I have not clearly understood the concepts. Thanks in advance.