8
\$\begingroup\$

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 :)

\$\endgroup\$

5 Answers 5

7
\$\begingroup\$

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.
\$\endgroup\$
6
\$\begingroup\$

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).

\$\endgroup\$
3
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Oct 1, 2010 at 10:31
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Oct 1, 2010 at 10:47
  • \$\begingroup\$ 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). \$\endgroup\$
    – user744
    Commented Oct 1, 2010 at 11:00
3
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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

\$\endgroup\$
-3
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .