DeSerialization to update content of object instead of construct new object
Hi
I am using boost serialization to synchronise objects between different
computers (network). The objects would be serializated as a string instead
of a file by using the class stringstream(instead of fstream). The string
would be transferred via TCP/IP layer.
Let simpify the situation as only two computers (Master and Slave) ,both of
two computers have N objects and I wanna synchronise their content. I create
a vector of pointer ( std::vector
The code for serialization of a vector is found in serialization/vector.hpp. I implemented this code to reconstuct the vector items rather than just reload them. I did this for a number of reasons - which for this discussion are not important. If this doesn't suit your needs, I would suggest you make your own version of serialization.hpp which operates differently. Starting with the current version it wouldn't be at all hard to do. If you want to use both current ("standard") method in some places in addition to your "custom" method, you might consider making some sort of wrapper which tags your special vectors with a type which can be distinguished for special serialization treatment. Robert Ramey Ng Pan wrote:
Hi
I am using boost serialization to synchronise objects between different computers (network). The objects would be serializated as a string instead of a file by using the class stringstream(instead of fstream). The string would be transferred via TCP/IP layer.
Let simpify the situation as only two computers (Master and Slave) ,both of two computers have N objects and I wanna synchronise their content. I create a vector of pointer ( std::vector
m_vpBase ) which points to the dirty objects. Both of two computers have this vector. Let assume the vectors are already pointing to the corresponding objects. For Tx side, it would serialize the objects as a string. For Rx side, I want to update the content of the objects that its vector is pointing to. Tx side: oa << BOOST_SERIALIZATION_NVP(m_vpBase);
Rx side: oa >> BOOST_SERIALIZATION_NVP(m_vpBase );
However, the above code would construct new objects.
What i want is just update the content of the objects , not construct new objects.
I know how to update the content for one object by using pointer ( base * m_pBase). Tx side: oa << BOOST_SERIALIZATION_NVP(m_pBase);
Rx side: oa >> BOOST_SERIALIZATION_NVP(*m_pBase);
But, I don't know how to do for a vector of pointer. If you know, please give me some hints. Thank you very much.
Regards Barr Ng [I found Boost serialization is useful and easy to use. ]
_________________________________________________________________ No masks required! Use MSN Messenger to chat with friends and family. http://go.msnserver.com/HK/25382.asp
Another, maybe easier option, could be to overload the serialization
functions for std::vector
The code for serialization of a vector is found in serialization/ vector.hpp.
I implemented this code to reconstuct the vector items rather than just reload them. I did this for a number of reasons - which for this discussion are not important.
If this doesn't suit your needs, I would suggest you make your own version of serialization.hpp which operates differently. Starting with the current version it wouldn't be at all hard to do.
If you want to use both current ("standard") method in some places in addition to your "custom" method, you might consider making some sort of wrapper which tags your special vectors with a type which can be distinguished for special serialization treatment.
Robert Ramey
Ng Pan wrote:
Hi
I am using boost serialization to synchronise objects between different computers (network). The objects would be serializated as a string instead of a file by using the class stringstream(instead of fstream). The string would be transferred via TCP/IP layer.
Let simpify the situation as only two computers (Master and Slave) ,both of two computers have N objects and I wanna synchronise their content. I create a vector of pointer ( std::vector
m_vpBase ) which points to the dirty objects. Both of two computers have this vector. Let assume the vectors are already pointing to the corresponding objects. For Tx side, it would serialize the objects as a string. For Rx side, I want to update the content of the objects that its vector is pointing to. Tx side: oa << BOOST_SERIALIZATION_NVP(m_vpBase);
Rx side: oa >> BOOST_SERIALIZATION_NVP(m_vpBase );
However, the above code would construct new objects.
What i want is just update the content of the objects , not construct new objects.
I know how to update the content for one object by using pointer ( base * m_pBase). Tx side: oa << BOOST_SERIALIZATION_NVP(m_pBase);
Rx side: oa >> BOOST_SERIALIZATION_NVP(*m_pBase);
But, I don't know how to do for a vector of pointer. If you know, please give me some hints. Thank you very much.
Regards Barr Ng [I found Boost serialization is useful and easy to use. ]
_________________________________________________________________ No masks required! Use MSN Messenger to chat with friends and family. http://go.msnserver.com/HK/25382.asp
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Matthias Troyer wrote:
Another, maybe easier option, could be to overload the serialization functions for std::vector
.
Actually - that sounds much simpler than my ideas. Robert Ramey
participants (3)
-
Matthias Troyer
-
Ng Pan
-
Robert Ramey