Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have been around programming for a while as a hobby, but I did not start seeing this concept until recently. I have google'd "what is serialization" numerous times, but I never actually get any sort of definition, usually just examples of how to do it. I am seeing it around the Ogre forums, the Bullet forums, and every other forum I go to, so I think it is about time I actually understand what it is, and why to use it.

Edit

To clarify, I am looking more for why to use it, especially in the sense of game programming. For example, the Bullet Physics API talks a lot about serializing a mesh, so I want to understand why that is.

Thank you :)

share|improve this question
add comment

5 Answers 5

up vote 5 down vote accepted

From the boost.serialization documentation: Here, we use the term "serialization" to mean the reversible deconstruction of an arbitrary set of C++ data structures to a sequence of bytes. Such a system can be used to reconstitute an equivalent structure in another program context. Depending on the context, this might used implement object persistence, remote parameter passing or other facility. In this system we use the term "archive" to refer to a specific rendering of this stream of bytes. This could be a file of binary data, text data, XML, or some other created by the user of this library.

In other words, serialization is any process that transforms objects in memory into some kind of bytestream, and deserialization does the reverse, taking a bytestream and transforming it back into objects in memory.

The term "serialization" does not imply anything about the format of the bytestream. It may be an efficiently packed binary format, or a loose XML or YAML description. It may even be source code in the original language itself, or in another programming language, such as JSON, which is a subset of JavaScript. The exact format of the serialized stream should be chosen based on how you intend to use it.

Serialization is a built-in feature of many languages and environments - for example Java and Python. In lower-level languages like C and C++, one must use (or write) serialization libraries, as the mechanism provided by the language is usually not good enough - it cannot follow or serialize pointers and references, and is subject to endianness issues, for example.

Wikipedia has a decent article on serialization.

Serialization is used extensively in games (and all software) for many purposes:

  • Loading the list of all spells in the game from resource files.
  • Saving and loading the game.
  • Recording the state of things (e.g. player positions and inventories) to a SQL or object database.
  • Invoking remote function calls over a network or other IPC link.
share|improve this answer
add comment

As I understand it, serialization is just the concept of taking an object or a set of objects, transforming them into a byte stream (for data storage, or network transmission, etc.) and then later reconstructing the original object from that bytestream ("deserialization").

Whimsical: It's a bit like a Star Trek teleporter, now I think of it.

A number of libraries exist for this, each of which deal with the little niggles that tend to get in the way (like bytestream endianness and such).

share|improve this answer
    
This makes sense, and I really like the teleporter analogy, that definitely helps comprehend it lol. Using serialization for networking makes perfect sense to me, but using it elsewhere, such as the Bullet Physics engine and there .bullet format, I don't understand where it is used there. –  Brett Powell Oct 1 '10 at 10:31
    
To further clarify my confusion, I found this simple tutorial codeproject.com/KB/cpp/serialization_primer1.aspx and on Step 3, it shows serializing data to a file. I don't understand how that is any different from just writing text to a file using fopen/fwrite, etc. –  Brett Powell Oct 1 '10 at 10:47
    
Serialization is the process of turning objects in your software into text that you can pass to fwrite (or whatever other bytestream-oriented reader/writer you need). –  user744 Oct 1 '10 at 11:00
add comment

To serialize something essentially means to change it into a series. This is necessary if you want to send something over a network or write it to a file, because both of those expect a series of bytes. So it's generally a fancy term for the save and load systems. In the case of Bullet, it's simply taking the mesh data and saving it out in a form that Bullet can effectively use. You can save this out and load it in later without needing to re-analyse your meshes.

share|improve this answer
add comment

Serialize/De-serialize is simply prepping and writing/reading objects to/from disk.

share|improve this answer
add comment

I personally use serialisation for networking. Outside of that I don't really have much use for it. If you want to know why it's used in Bullet, the best chance you have of getting an answer is by asking in the Bullet forums or reading the documentation.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.