Re: Boost serialization of intrusive_ptr?

Discussion in 'C++' started by Francesco, Sep 2, 2009.

  1. Francesco

    Francesco Guest

    On 2 Set, 03:42, Bradley Wilson <> wrote:

    [snip]

    > So unless some wizard out there has already figured out a way around
    > this problem,
    > I'm going to have to alter my approach to how to save state. (I have an
    > idea, but
    > it's madness.)


    What about a table lookup?

    Caveat: this is just a theoretical rant, I never used boost or
    anything like a memory pool.

    Add a unique ID to all of your objects and, when serializing, save to
    disk the IDs of the objects along with their owners and along with the
    objects that link to that(those) owner(s).

    When unserializing, create a table to lookup the ID->new_pointer pairs
    then set the pointers accordingly as you proceed.

    This should work fine as long as you respect the order of
    serialization-unserialization (owners first, linkers last), and this
    becomes really tricky during the unserialization if the objects link
    to each other in a cyclic manner.

    Just half a cent, I know. I could expose my idea better with an
    example, if you want, but my example would take complete care of the
    serialization-unserialization process, then it would be your task to
    fit this technique into your program.

    Hope that helps, anyway.

    Best regards,
    Francesco
    Francesco, Sep 2, 2009
    #1
    1. Advertising

  2. Francesco

    Francesco Guest

    On 2 Set, 04:41, Francesco <> wrote:
    > On 2 Set, 03:42, Bradley Wilson <> wrote:
    >
    > [snip]
    >
    > > So unless some wizard out there has already figured out a way around
    > > this problem,
    > > I'm going to have to alter my approach to how to save state. (I have an
    > > idea, but
    > > it's madness.)

    >
    > What about a table lookup?
    >
    > Caveat: this is just a theoretical rant, I never used boost or
    > anything like a memory pool.
    >
    > Add a unique ID to all of your objects and, when serializing, save to
    > disk the IDs of the objects along with their owners and along with the
    > objects that link to that(those) owner(s).
    >
    > When unserializing, create a table to lookup the ID->new_pointer pairs
    > then set the pointers accordingly as you proceed.
    >
    > This should work fine as long as you respect the order of
    > serialization-unserialization (owners first, linkers last), and this
    > becomes really tricky during the unserialization if the objects link
    > to each other in a cyclic manner.
    >
    > Just half a cent, I know. I could expose my idea better with an
    > example, if you want, but my example would take complete care of the
    > serialization-unserialization process, then it would be your task to
    > fit this technique into your program.


    Thinking better - yesterday I missed the point - I suppose you have to
    store to disk both the objects' data and the pointers' data (the
    addresses they point to, that actually can be used as IDs on disk).

    The main problem with the serialization you are currently doing is
    that some pointers aren't serialized at all (namely, the "b" pointer
    of your latest post, whose data-dumping gets skipped because of the
    swizzling). Once you don't serialize the data of that pointer (that
    is, the address it points to) there is no chance to recover the links
    later.

    Another half a cent, I know. I should put my hands on boost to get a
    better grip on your problem.

    Hope that helps - again, anyway.

    Cheers,
    Francesco
    Francesco, Sep 2, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    2,240
    deadsea
    Jan 2, 2005
  2. Steven T. Hatton

    #include <boost/intrusive_ptr.hpp>

    Steven T. Hatton, Jun 15, 2005, in forum: C++
    Replies:
    4
    Views:
    2,623
    Steven T. Hatton
    Jun 15, 2005
  3. Replies:
    3
    Views:
    1,024
  4. Pallav singh

    shared_ptr<T> vs intrusive_ptr<T>

    Pallav singh, Apr 28, 2009, in forum: C++
    Replies:
    1
    Views:
    1,412
    Noah Roberts
    Apr 28, 2009
  5. Bart van Ingen Schenau

    Re: Boost serialization of intrusive_ptr?

    Bart van Ingen Schenau, Sep 2, 2009, in forum: C++
    Replies:
    0
    Views:
    596
    Bart van Ingen Schenau
    Sep 2, 2009
Loading...

Share This Page