Pointer Odyssey

Hi there,

How do I serialize a pointer so that when I deserialize my file my objects are returned to the "same" pointer? I've been struggling with this for a week. I'm not confident in my thought solution but here is how I think it should work:

Independent thing:
Step 1: create vectors for holding the address and some arbitrary value
Step 2: serialize the thing, push_back the address and value++
Step 3: write the value to file.
Dependent thing:
Step 4: after serializing, compare addresses if match write the associated value to file

From file:
Independent thing:
Step 1: deserialize thing, store address along with value from file
Dependent thing:
Step 2: compare value read to values stored and return the address of the independent thing. The dependent object should be home now.
Step 3: clean up

After writing I realize a vector of objects with a void* and some value will be superior to two vectors.

What are your thoughts on this? Are there ways I can improve upon this?
Thank you so much for you time.

edit: what about just writing the address of the independent to the file instead of an arbitrary value?
Last edited on
I don't understand your algorithm.

There's many ways to do serialization. The specifics will depend primarily on the complexity of your object graph (i.e. how are your objects interconnected?): Do you just need to serialize a linear array? A tree? A directed acyclic graph? A general graph? Are your objects simple C structs or are they more complex? Do you need to serialize instances of classes that use multiple inheritance?

There are libraries that let you describe your data structures in some notation and automatically generate the de/serialization code.
* Google Protobuf
* Apache Avro
* Cap'n Proto
* My own library. It handles general graphs and class hierarchies with multiple inheritance: https://github.com/Helios-vmg/cppserialization/ :)
My own library. It handles general graphs and class hierarchies with multiple inheritance

That's really cool helios! I read through the LAS readme and I'm going to try it out.
I'm slightly concerned about the only full deserialization limitation, its probably something that takes getting used to.
Thanks for the good recommendations and potentially saving me a lot of time.
Topic archived. No new replies allowed.