I have been trying to do this job for a long time.
There are 6 classes in my project that are serialized using the exact boost guide, by implementing template serialization.
These classes are: State, guState, Policy, Action, Param, Vec3D.
When I serialize and save them, it works great. I get a really text file with different numbers and lines.
No complaints, no warnings, no exceptions. The only case: if I try to serialize the class pointer element, the hole process will become a zombie. Therefore, I am not trying to do this and save work.
When I try to download, I get:
end of call after calling instance of 'boost :: archive :: archive_exception' what (): stream error
Now the interesting part is that I am serializing two boost :: ptr_vectors, one of which consists of status pointers and one that consists of policy pointers.
The state vector, I saved and loaded without problems. The policy vector I can save, but when I try to load, I get an exception.
In addition, after reading the tutorials to enhance, I got the impression that I didn't need anything else to download except the serialization function.
However, when I tried to load, the serialization boost would complain about not looking for a default constructor like State (), Policy (), etc. (I implement my own constructors in each class).
After reading this tutorial here, I applied a default constructor that does nothing, so serialization work will work. Indeed, it compiled, and I got the results mentioned above.
I tried to go down the difficult road seen in my old question here , where I tried to split and implement save_construct_data and load_construct_data, but I found it too inlaid, again I got the exact error as above.
Can someone please help me, explain how loading works, what is the deal with default constructors? Or at least give me a link that might be helpful. I went through the boost manuals and they say little about reconstruction.
Thanks.
Edit (several fragments added)
class State { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version); protected: std::map<std::string,float> positions; float reward; std::size_t hash_value; bool exists(const Action* A); bool operator== (State const& S); std::size_t hash(); void clean_noise(); State(){};
Other classes that inherit from the state also have their serialization functions, using:
ar & boost::serialization::base_object<State>(*this);
Class Policy:
class Policy { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version); Policy() {};
As you can see, these are two main classes. Other classes are also serialized due to recovery dependencies (Action class, Param class, etc.)
Master Class:
template <class S, class P> class Task { protected: ...
Effectively contains two boost :: ptr_vectors that contain states and policies. States are saved and loaded without problems.
The problem occurs when loading policies. Saving them does not create a problem (but again, I could be wrong).
Test save / load without policies and with. The problem is with policy recovery.
Note the default constructors used only by serialization, without which the code would not compile.
EDIT # 2: after starting the application using valgrind and memcheck, it reports that there is a pointer memory leak. However, since I am not good at debugging with valgrind, I cannot tell where the leak is occurring, or if it is relevant to my serialization (I think it is).