1

I would like to serialize an object via a boost::shared_ptr. My application has a main loop where it modifies the object and then serializes it, each cycle. The result is that the value (i.e. member fields) of the object are saved only once, which is not what I want -- I would like to save both object tree structure and object member fields. What is the recommended way to achieve this?

dkrikun
  • 1,228
  • 1
  • 15
  • 23

1 Answers1

1

You need to do one of he following:

  • disable object tracking (read Class Serialization Traits -> Object Tracking), otherwise objects with equivalent pointers will be assumed to have the same identity, and only be included once per archive
  • serialize a value, instead of by pointer (this could be problematic for polymorphic types)
  • start a new archive each time (warning: this can have considerable overhead: Boost C++ Serialization overhead)
Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Why the need to start a new archive though? – dkrikun Jun 01 '14 at 12:57
  • @dkrikun You can pick one fo the approaches. See also **[Boost::Serialization: How to avoid the double-saving of a pointer?](http://stackoverflow.com/a/23458397/85371)** (around the _"But hey! Isn't Boost Serialization to do object tracking when serializing pointers?"_ remark) – sehe Jun 01 '14 at 12:57