The problem is is that de-serializing a pointer creates a new object in a new address. Now one comes along an deseriailzed the same object to a fixed address. There is no way to fix this without going back to the begining. This situation is detected though tracking and a "pointer conflict" exception is thrown. The solution is to be sure that if objects are serialized directly and through pointers, the the pointer serialization is done second. Robert Ramey Ivan Rachev wrote:
Robert Ramey wrote:
This is a different problem.
DynamicArray<A> ArrayOfAs; ArrayOfAs.Element = new A[5]; ArrayOfAs.Size = 5; A* secondElement = &ArrayOfAs.Element[1];
std::stringstream stream; { boost::archive::text_oarchive oa(stream); oa & secondElement; // new object created here oa & ArrayOfAs; // attempt to reload an already loaded object
to new address - throw exception - pointer conflict
}
I think over here we have a solution to try.
I believe at saving boost::serialization creates a map (object address -> object id) and at loading the lib creates the reverse map (object id -> object address)
How inside the archive could I write a function like this: ObjID GetObjectID(void* objectAddress);
Usage will be like this: class A { template<class Archive> void save(Archive & ar, const unsigned int version) const { ... ObjID objId = ar.GetObjectID(this); ... }
};
Also, after loading is done and the load map is created, how inside the archive could I implement a function like this: void* GetObjectAddress(ObjID objId);
Usage will be like this: ... ObjID objId; std::stringstream stream; boost::archive::text_iarchive ia(stream); ia & someObj; ia & objId; void* p = ar.GetObjectAddress(objId); ...
Ivan