[serialization] Serializing array of POD or custom type
Hi everyone.
I'm trying to work out how you serialize arrays using the boost
serializer. Here's a simplified example:
struct node_link
{
u32 node_A;
u32 node_B;
};
struct Node {
node_link* m_node_links_array;
int m_node_links_size;
};
// non-intrusive serialization
template<class Archive>
void serialize(Archive & ar, node_link& link, const unsigned
int version)
{
ar & link.node_A;
ar & link.node_B;
}
template<class Archive>
void serialize(Archive & ar, Node& node_data, const unsigned
int version)
{
ar &
boost::serialization::array
2012/6/26 Kim Gadecki
Hi everyone.
I'm trying to work out how you serialize arrays using the boost serializer. Here's a simplified example:
struct node_link { u32 node_A; u32 node_B; };
struct Node { node_link* m_node_links_array; int m_node_links_size; };
// non-intrusive serialization template<class Archive> void serialize(Archive & ar, node_link& link, const unsigned int version) { ar & link.node_A; ar & link.node_B; }
template<class Archive> void serialize(Archive & ar, Node& node_data, const unsigned int version) { ar & boost::serialization::array<**node_link>(node_data.m_node_ **links_array, node_data.m_node_links_size); ar & node_data.m_node_links_size; }
I'm guessing: how is deserialization of an array supposed to work, if size is deserialized afterwords? Regards Kris
On 6/26/2012 3:56 PM, Krzysztof Czainski wrote:
2012/6/26 Kim Gadecki
mailto:gadecki@iinet.net.au> Hi everyone.
I'm trying to work out how you serialize arrays using the boost serializer. Here's a simplified example:
struct node_link { u32 node_A; u32 node_B; };
struct Node { node_link* m_node_links_array; int m_node_links_size; };
// non-intrusive serialization template<class Archive> void serialize(Archive & ar, node_link& link, const unsigned int version) { ar & link.node_A; ar & link.node_B; }
template<class Archive> void serialize(Archive & ar, Node& node_data, const unsigned int version) { ar & boost::serialization::array
(node_data.m_node_links_array, node_data.m_node_links_size); ar & node_data.m_node_links_size; } I'm guessing: how is deserialization of an array supposed to work, if size is deserialized afterwords?
Regards Kris
Right you are. It also looks like you need to manually allocate memory
for the array:
ar & node_data.m_node_links_size;
node_data.m_node_links_array = new
node_link[node_data.m_node_links_size];
ar &
boost::serialization::array
participants (2)
-
Kim Gadecki
-
Krzysztof Czainski