
Hi!
I want to serialize objects that link to each other through pointers, like a
linked list, but in this case a more complex graph with several different
classes and proxies (a graph which can contain loops and and null-pointers).
But I get the "pointer conflict" exception since the serialization discovers
that an object have been serialized once before through its pointer. The
contents should be serialized/deserialized only once, and then the pointers
should just be kept consistent.
An alternative is of course to replace all the pointers with indeces which are
memory-independent. But that's a messy affair.
In the copy constructor I solved something similar through a map

This should work - How is your case different that test_cycle.cpp ? The pointer conflict means that something has been serializaed as first as a pointer then as an object. Normally this should be easily avoidable. This is flagged as an error because the de-serialization would be a problem. First the deserialization of a pointer creates an object - next the object itself is re-loaded - but now we have two objects when we started with one. Robert Ramey Henrik Jacobsson wrote:
Hi!
I want to serialize objects that link to each other through pointers, like a linked list, but in this case a more complex graph with several different classes and proxies (a graph which can contain loops and and null-pointers).
But I get the "pointer conflict" exception since the serialization discovers that an object have been serialized once before through its pointer. The contents should be serialized/deserialized only once, and then the pointers should just be kept consistent.
An alternative is of course to replace all the pointers with indeces which are memory-independent. But that's a messy affair.
In the copy constructor I solved something similar through a map
which mapped from the old pointers to the newly allocated ones, so that they could be properly replaced. Is something like this hidden somewhere in the lib? Any suggestions?
Best regards, Henrik Jacobsson

Robert Ramey wrote:
This should work - How is your case different that test_cycle.cpp ?
I can't find test_cycle.cpp unfortunately, so I don't know. See my example below.
The pointer conflict means that something has been serializaed as first as a pointer then as an object. Normally this should be easily avoidable. This is flagged as an error because the de-serialization would be a problem. First the deserialization of a pointer creates an object - next the object itself is re-loaded - but now we have two objects when we started with one.
I see what you mean, but I fail how to see a convenient way to avoid it without
changing all containers so that they have pointers instead of objects or
something like that. Is perhaps BOOST_CLASS_TRACKING the key?
---
#include <vector>
#include <fstream>
#include
Robert Ramey
Henrik Jacobsson wrote:
Hi!
I want to serialize objects that link to each other through pointers, like a linked list, but in this case a more complex graph with several different classes and proxies (a graph which can contain loops and and null-pointers).
But I get the "pointer conflict" exception since the serialization discovers that an object have been serialized once before through its pointer. The contents should be serialized/deserialized only once, and then the pointers should just be kept consistent.
An alternative is of course to replace all the pointers with indeces which are memory-independent. But that's a messy affair.
In the copy constructor I solved something similar through a map
which mapped from the old pointers to the newly allocated ones, so that they could be properly replaced. Is something like this hidden somewhere in the lib? Any suggestions?
Best regards, Henrik Jacobsson
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

also sprach Robert Ramey
This should work - How is your case different that test_cycle.cpp ?
If you are talking about test_cyclic_ptrs.cpp, how does that actually show that it works? It just states in a comment that it cannot be made to work, and the test_main code actually assumes that it won't work: BOOST_CHECK( exception.code == boost::archive::archive_exception::pointer_conflict );
The pointer conflict means that something has been serializaed as first as a pointer then as an object. Normally this should be easily avoidable.
What about the cases when it's not easily avoidable? In a related thread, I asked the question of how to serialise a linked list. node::serialize() { if (this->next) serialize *(this->next); serialize this->next; } this (recursive) approach will work (I think). But what if I have to use iteration? Or if I serialise a graph, where a number of pointers to a node may exist? Do I really have to go through the lengths to ensure that the Nodes are serialised first?
This is flagged as an error because the de-serialization would be a problem. First the deserialization of a pointer creates an object - next the object itself is re-loaded - but now we have two objects when we started with one.
Couldn't it just assign the already-created object to the non-pointer? From what I understand, serialising *P then P is the same as serialising P then *P: the first time, the entire object is dumped. The second time, a reference is written instead. Thus, on first creation, everything is already known about the object. And when the non-pointer needs to be serialised, then we don't return a pointer, but a reference... -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck invalid/expired pgp subkeys? use subkeys.pgp.net as keyserver! spamtraps: madduck.bogus@madduck.net scientists will study your brain to learn more about your distant cousin, man.

I stand corrected. test_cyclic_ptr doesn't quite test what I thought it did. So cyclic objects can't be serialized. cyclic object pointers can be serialized with no special effort. Robert Ramey

also sprach Robert Ramey
cyclic objects can't be serialized. cyclic object pointers can be serialized with no special effort.
I am starting to feal nausea. Hoever, given that I somewhat misunderstood non-pointer deserialisation, it makes perfect sense, and I cannot conceive a good solution. Well, except for serialising and deserialising only pointers. So now I have to figure out how to prevent wads of memory "leaks" trying to determine when to delete those pointers again. -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck invalid/expired pgp subkeys? use subkeys.pgp.net as keyserver! spamtraps: madduck.bogus@madduck.net "'this must be a thursday,' said arthur to himself, sinking low over his beer. 'i never could get the hang of thursdays.'" -- hitchhiker's guide to the galaxy

also sprach martin f krafft
Well, except for serialising and deserialising only pointers. So now I have to figure out how to prevent wads of memory "leaks" trying to determine when to delete those pointers again.
This makes me think: has anyone successfully plugged in your own allocator and/or factory into Robert's serialization framework? -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck invalid/expired pgp subkeys? use subkeys.pgp.net as keyserver! spamtraps: madduck.bogus@madduck.net "self-denial is the shining sore on the leprous body of christianity." -- oscar wilde

martin f krafft wrote: This makes me think: has anyone successfully plugged in your own allocator and/or factory into Robert's serialization framework? Now you're making me dizzy. Robert Ramey

also sprach Robert Ramey
Now you're making me dizzy.
No, really. I need to use a pool allocator for my objects. Are you telling me I cannot? -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck invalid/expired pgp subkeys? use subkeys.pgp.net as keyserver! spamtraps: madduck.bogus@madduck.net after you install windows xp, you have the option to create user accounts. if you create user accounts, by default, they will have an account type of administrator with no password. way to go!

martin f krafft wrote: No, really. I need to use a pool allocator for my objects. Are you telling me I cannot? No, I'm just saying I don't think anyone has done it. Honestly, I don't know if I made any accidental assumptions regarding allocators in the package. I would be please to see someone try this and report any problems. Then we could add a test and have one more thing certified as working. Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

also sprach Robert Ramey
No, I'm just saying I don't think anyone has done it. Honestly, I don't know if I made any accidental assumptions regarding allocators in the package. I would be please to see someone try this and report any problems. Then we could add a test and have one more thing certified as working.
Ha! I can't even find the place where space is allocated. It's not *_construct_data, as here the space already exists. Could you point me to some place where the allocation is being done during deserialisation of a pointer? -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck invalid/expired pgp subkeys? use subkeys.pgp.net as keyserver! spamtraps: madduck.bogus@madduck.net when compared to windoze, unix is an operating system.

cyclic objects can't be serialized. cyclic object pointers can be serialized with no special effort.
A simple, and probably naive, idea... Since pointers mean no problems and objects do, would it not be possible to have an option "serialize_object_as_pointer" and for containers "serialize_members_as_pointers" in the library, as a means to circumvent this? That way one would not have to change the implementation of all containers of cyclic objects into containers of pointers... Alternatively, or additionally, within the cyclic object themselves, it would be nice if it was possible to serialize the pointer without serializing its contents, i.e. creating only an index in the archive, making it up to the user to make sure that the object is later serialized with that index to adress it. The order of serialized contents will then be in the order of preference of the user. Deserialization may become a nightmare then, I suppose... But still, it would be nice with that kind of control over the order of serialization... // Henrik Jacobsson
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Henrik Jacobsson wrote:
cyclic objects can't be serialized. cyclic object pointers can be serialized with no special effort.
A simple, and probably naive, idea... Since pointers mean no problems and objects do, would it not be possible to have an option "serialize_object_as_pointer" and for containers "serialize_members_as_pointers" in the library, as a means to circumvent this? That way one would not have to change the implementation of all containers of cyclic objects into containers of pointers...
I don't think this would work for a couple of reasons - mainly that if you save objects that arn't pointers, the loader would create pointers and you wouldn't have the same thing that you started with.
Alternatively, or additionally, within the cyclic object themselves, it would be nice if it was possible to serialize the pointer without serializing its contents, i.e. creating only an index in the archive, making it up to the user to make sure that the object is later serialized with that index to adress it.
That's more or less how the serialization of pointers works now - and that's why it DOES work. Robert Ramey

also sprach Robert Ramey
Alternatively, or additionally, within the cyclic object themselves, it would be nice if it was possible to serialize the pointer without serializing its contents, i.e. creating only an index in the archive, making it up to the user to make sure that the object is later serialized with that index to adress it.
That's more or less how the serialization of pointers works now - and that's why it DOES work.
If I end up not serialising the pointee object, the framework does serialise it automatically, right? That is to say: { A a; a.x = 5; ar << &a; } //... A *b ar >> b; assert(b->x == 5) should work just fine, right? -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck invalid/expired pgp subkeys? use subkeys.pgp.net as keyserver! spamtraps: madduck.bogus@madduck.net "men always want to be a woman's first love. women have a more subtle instinct: what they like is to be a man's last romance." -- oscar wilde

martin f krafft wrote:
Alternatively, or additionally, within the cyclic object themselves, it would be nice if it was possible to serialize the pointer without serializing its contents, i.e. creating only an index in the archive, making it up to the user to make sure that the object is later serialized with that index to adress it.
That's more or less how the serialization of pointers works now - and that's why it DOES work.
If I end up not serialising the pointee object, the framework does serialise it automatically, right? That is to say: { A a; a.x = 5; ar << &a; } //... A *b ar >> b; assert(b->x == 5) should work just fine, right? That should work. for symetry I would have written { const A *a = new A(5); ... ar << a; ... A *new_a; ... ar >> new_a .. assert(*a == *new_a); } Note the slightly trick usage of const in this example which has been the subject of recent posts and is explained in the manual section describing tracking. Robert Ramey

{ A a; a.x = 5; ar << &a; }
That should work.
{ const A *a = new A(5); ... ar >> new_a .. assert(*a == *new_a); }
I wanted to make it explicit that a goes out of scope after its one and only serialisation. -- martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck invalid/expired pgp subkeys? use subkeys.pgp.net as keyserver! spamtraps: madduck.bogus@madduck.net the only real advantage to punk music is that nobody can whistle it.
participants (3)
-
Henrik Jacobsson
-
martin f krafft
-
Robert Ramey