0

I have been reading through all that I could find to understand what Serialization is. People often say that we need serialization so that we can convert the in-memory object into a form that is easy to transport over the network and persist on the disk.

My question is - What is so wrong with the in-memory object's structure that makes it difficult to be transported or stored?

Some people also say that the object is binary in form and needs to be serialized. AFAIK, everything in the computer storage or memory is binary. What is it that they want to convey?

Some technical details would be appreciated.

EDIT 1:

I have been looking into C# code samples but all of them use the "Serialization" available in the framework. Maybe I need to work with C++ to see the details and to experience the pain.

msiyer
  • 821
  • 6
  • 20
  • I suggest you try it to see what the difficulties are. We can tell you, but seeing it for yourself is much more valuable. For example, in memory uses addresses which you cannot use, and objects have headers which you don't want. The objects can use more memory than you really need to transmit the data as being more compact can be more important than being fast. Also consider what happens when A refers to B and B refers to A. How do you send and rebuild that? – Peter Lawrey Aug 06 '13 at 09:10

2 Answers2

1

A simple and obvious example; a file object is a reference to a file in the file system, but in itself not very useful. Serializing it will at best pass a filename to the receiver, which may not have the file system to read the file from.

Instead, when you pass it over the network, you can serialize it to instead contain the contents of the file, which is usable by the receiver.

Serializing is basically just taking an object which in memory may not have very usable content (pointers/references to data stored elsewhere/...), and converting it to something that is actually usable by the receiver.

Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
1

For instance, if you have an object of this class

 public class myClass {
   private String myString = null;

   // getters and setters
 }

The in memory representation will be the just a pointer to another object (the String). You cannot recall the original state of the object just by storing the binary form.

SJuan76
  • 24,532
  • 6
  • 47
  • 87