Sign in to follow this  

hierarchical serialization

This topic is 3589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it better to use hierarchical serialization when serializing objects that contain other objects or just to create a function that acceses variables from the object. for example if i were to serialize a face object that stored a certain amount of vertex objects and a texture would i be better off with:
#include <stdio.h>

void Face::serialize(FILE * file) {
   for(int a = 0; a < number of vertices; a++) {
      vertex[a].serialize(file);
   }
   texture.serialize(file);
}


or with a function like:
#include <stdio.h>

void Face::serialize(FILE * file) {

   for(int a = 0; a < number of vertices; a++) {
      fputc(vertex[a].x, file);
      fputc(vertex[a].y, file);
      fputc(vertex[a].z, file);
   }

   // however you would serialize a texture
}


this is just an example, you probaly wouldn't use one byte for each vertex's x, y and z, but you get the idea.

Share this post


Link to post
Share on other sites
Of the two examples you gave, I'd go with the first (although I'd recommend using file stream objects rather than C-style file IO, since you appear to be using C++).

Also, you might take a look at the Boost Serialization library - it provides basically the same functionality as in your example, and takes care of many of the details of the serialization process for you.

Share this post


Link to post
Share on other sites

This topic is 3589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this