Serialization vs. Archiving?
Asked Answered
S

3

7

The iOS docs differentiate between "serializing" and "archiving." Is this a general distinction (i.e., holds in other languages) or is it specific to Objective-C? Also, what is the difference between these two?

Shuler answered 26/11, 2010 at 21:46 Comment(2)
@skaffman, I precisely didn't want this tagged iOS so that I could get some answers from other languages.Shuler
It isn't even specific to iOS. NSKeyedArchiver is available on Mac OS X too.Equivalence
P
7

This is a case of one being the other some (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 across a network connection link to be "resurrected" later in the same or another computer environment"

So, archiving may only be serialization, but it could also be the combination of serialization and compresssion, for example. Or perhaps it adds some kind of header info. So serialization is a form of archive, but an archive is not necessarily a serialization.

This isn't really specific to iOS - these terms are thrown around all over. Their specific meaning in the context of iOS could be quite specific, though.

Photographic answered 26/11, 2010 at 21:55 Comment(1)
Great answer +1. I in fact had it all backwards.Shuler
O
6

I was actually trying to look for their difference from IOS perspective. Adding the following for people interested :

Purpose:
Archiving is used to store object graphs. complete data model can be archived and restored easily. The way Nib files work can be considered as example for archiving.

Serialization is used for storing arbitrary hierarchy of objects.
The wat plist files work can be considered as example fo serializations.

Differences(excerpts from Archives programing guide):
"The archive preserves the identity of every object in the graph and all the relationships it has with all the other objects in the graph."
Every object encoded within the context of rootObject invocation is tracked. If the coder is asked to encode an object more than once, the coder encodes a reference to the first encoding instead of encoding the object again.

"The serialization only preserves the values of the objects and their position in the hierarchy. Multiple references to the same value object might result in multiple objects when deserialized. The mutability of the objects is not maintained."

Implementation differences:
Any object that implements NSCoding protocol can be archived where as 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 must also contain only objects of these few classes.

When to Use:
property lists(serialization) should be used for data that consists primarily of strings and numbers. They are very inefficient when used with large blocks of binary data.
It is worthy to Archive objects other than plist objects or storing large blocks of data.

Outshout answered 7/6, 2011 at 5:17 Comment(0)
I
1

Generally speaking, Serialization is concerned with converting your program data types into architecture independent byte streams. Archiving is specialized serialization in that you could store type and other relationship based information that allow you to unserialize/unmarshall easily. So archival can be thought of as a specialization and subset of Serialization. For Objective-C

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

With C++ boost serialization --

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

Itching answered 26/11, 2010 at 22:16 Comment(2)
Cool +1. This helps me separate. I'm holding out for more examples rom other languages.Shuler
If Archiving is specialized serialization, doesn't that mean that archival can be thought of as a specialization and s̶u̶b̶s̶e̶t̶ superset of Serialization? as it contains more than just serialization. EDIT: sorry, I got it. Actually, archiving is more restrictive than serialization so what you said is correct.Biestings

© 2022 - 2024 — McMap. All rights reserved.