Jump to content
  • Advertisement
Sign in to follow this  
staticVoid2

hierarchical serialization

This topic is 3838 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!