Serialization and archiving?

iOS docs distinguish between serialization and archiving. Is this a general difference (i.e., running in other languages) or is it specific to Objective-C? Also, what is the difference between the two?

+6
serialization nskeyedarchiver
source share
3 answers

This is the case when one of them is the other (but not all) of the time.

Wikipedia has this to say about serialization:

"Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer or transmitted over a network connection line to be resurrected later in the same or another computer environment."

Thus, archiving can only be serialization, but, for example, it can be a combination of serialization and compression. Or maybe it adds some kind of header information. Thus, serialization is a form of archive, but an archive is not necessarily serialization.

This is not very specific to iOS - these terms are thrown around the world. However, their specific meaning in the context of iOS can be very specific.

+5
source share

I really tried to find their difference from the iOS perspective. Adding the following to interested people:

Purpose:
Archiving is used to store graphs of objects. A complete data model can be easily archived and restored. The way Nib files work can be seen as an example for archiving.

Serialization is used to store an arbitrary hierarchy of objects.
The work of wat plist files can be seen as an example for serialization.

Differences (excerpts from the archive programming guide):
"The archive preserves the identity of each object in the graph and all the relationships that it has with all other objects on the graph."
Each object encoded in the context of calling rootObject is tracked. If the encoder is asked to encode an object more than once, the encoder encodes a link to the first encoding instead of encoding the object again.

"Serialization only stores the values ​​of objects and their position in the hierarchy. Multiple references to the same value object can lead to several objects during deserialization. Object variability is not supported."

Differences in implementation:
Any object that implements the NSCoding protocol can be archived where only instances of NSArray, NSDictionary, NSString, NSDate, NSNumber and NSData (and some of their subclasses) can be serialized. The contents of array and dictionary objects should also contain only objects from these several classes.

When to use:
property lists (serialization) should be used for data that consists mainly of strings and numbers. They are very inefficient when used with large blocks of binary data.
It is enough to archive objects other than plist objects, or to store large data blocks.

+6
source share

Generally speaking, serialization involves converting your program data types into architecture-independent byte streams. Archiving is a specialized serialization in which you can store information about the type and other relationships based on relationships that make it easy to reset / unarmore. Thus, archiving can be seen as a specialization and a subset of serialization. For Objective-C

Serialization converts Objective Styles to and from architecture-independent byte stream. Unlike archiving, basic serialization does not record data type values, relationships between them; only the recordings themselves are recorded. It is your responsibility to deserialize the data in the proper manner. Several convenience classes, however, do provide the ability to serialize property lists, recording their structure along with their values.

With serialization with C ++ boost -

http://www.boost.org/doc/libs/1_45_0/libs/serialization/doc/index.html

Here we use the term “serialization” to mean the reversible deconstruction of an arbitrary data set of a C ++ structure into a sequence of bytes. Such a system can be used to recreate an equivalent structure in a different program context. depending on the context, this could be used to implement object persistence, remote parameter passing, or another object. In this system, we use the term “archive” to refer to a specific rendering of this byte stream. This can be a binary data file, text data, XML, or some other user-created this library.

+1
source share

All Articles