Boost logo

Boost Users :

From: Ivan Rachev (ivanr_at_[hidden])
Date: 2005-07-16 11:17:51


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


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