序列化与归档?

发布于 2024-10-04 10:42:27 字数 80 浏览 6 评论 0原文

iOS 文档区分了“序列化”和“归档”。这是一个普遍的区别(即,在其他语言中也是如此)还是特定于 Objective-C?另外,这两者有什么区别?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清醇 2024-10-11 10:42:27

这是一种有时(但不是全部)一个人成为另一个人的情况。

维基百科关于序列化是这样说的:

“序列化是将数据结构或对象转换为位序列的过程,以便可以将其存储在文件或内存缓冲区中,或者通过网络连接链路进行传输以“复活”稍后在相同或另一个计算机环境中”

因此,归档可能只是序列化,但也可以是序列化和压缩的组合。或者它可能添加某种标头信息。所以序列化是存档的一种形式,但存档不一定是序列化。

这并不是 iOS 特有的——这些术语到处都是。不过,它们在 iOS 环境中的具体含义可能非常具体。

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.

温馨耳语 2024-10-11 10:42:27

我其实是想从IOS的角度来寻找它们的区别。为感兴趣的人添加以下内容:

目的:
归档用于存储对象图。完整的数据模型可以轻松归档和恢复。 Nib 文件的工作方式可以视为归档的示例。

序列化用于存储对象的任意层次结构。
wat plist 文件工作可以被视为序列化的示例。

差异(摘自 Archives 编程指南):
“存档保留了图中每个对象的身份以及它与图中所有其他对象的所有关系。”
跟踪 rootObject 调用上下文中编码的每个对象。如果要求编码器多次对某个对象进行编码,则编码器会对第一次编码的引用进行编码,而不是再次对对象进行编码。

“序列化仅保留对象的值及其在层次结构中的位置。对同一值对象的多个引用可能会在反序列化时产生多个对象。不会维护对象的可变性。”

实现差异:
任何实现 NSCoding 协议的对象都可以被归档,其中只有 NSArray、NSDictionary、NSString、NSDate、NSNumber 和 NSData(及其一些子类)的实例可以被序列化。数组和字典对象的内容也必须仅包含这几个类的对象。

何时使用:
属性列表(序列化)应用于主要由字符串和数字组成的数据。当与大块二进制数据一起使用时,它们的效率非常低。
除了 plist 对象或存储大数据块之外,归档对象也是值得的。

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.

闻呓 2024-10-11 10:42:27

一般来说,序列化涉及将程序数据类型转换为与体系结构无关的字节流。归档是专门的序列化,因为您可以存储类型和其他基于关系的信息,使您可以轻松地反序列化/解组。因此,归档可以被认为是序列化的专业化和子集。对于 Objective-C

序列化转换 Objective-C
类型与
与体系结构无关的字节流。
与归档相比,基本
序列化不记录数据
值的类型或
他们之间的关系;只有
值本身被记录。这是
你有责任反序列化
数据按正确的顺序排列。一些
然而,便利课程确实
提供序列化的能力
财产清单,记录其
结构及其值。

使用 C++ boost 序列化 -

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

在这里,我们使用术语“序列化”
意味着可逆解构
任意一组 C++ 数据
结构到字节序列。
这样的系统可用于
重建等效结构
在另一个程序上下文中。取决于
在上下文中,这可能会被使用
实现对象持久化、远程
参数传递或其他设施。
在这个系统中我们使用术语
“档案”指的是特定的
渲染该字节流。
这可能是一个二进制数据文件,
文本数据、XML 或其他创建的数据
由该库的用户编写。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文