Persistence VS Serialization

本文详细解释了计算机科学中持久化和序列化的概念及其应用。持久化是指状态能够超越创建它的进程而存在的一种特性;序列化则是将数据结构或对象转换为可以存储或在网络中传输的格式的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Persistence in computer science refers to the characteristic of state that outlives the process that created it.

2. Serializatioin. In computer science, in the context of data storage and transmission, serialization is the process of converting a data structure or object into a format that can be stored (for example, in a file or memory buffer, or transmitted across a network connection link) and "resurrected" later in the same or another computer environment.[1] When the resulting series of bits is reread according to the serialization format, it can be used to create a semantically identical clone of the original object. For many complex objects, such as those that make extensive use of references, this process is not straightforward.

This process of serializing an object is also called deflating or marshalling an object.[2] The opposite operation, extracting a data structure from a series of bytes, is deserialization (which is also called inflating or unmarshalling).

3. Serialization is just the ability to convert an object into a stream. It can be used for persistence, such as saving the stream to a file (or a DB). But it can also be used for other stuff too. For example, you can send the stream to another machine on the network to deserialize -- in that example, serialization is the transport to get an object across the network.

Peristence is the ability of an object to save its state. You can use serialization for this. Or you can just save your own variables to a file. Or a DB. Or a network service. Etc. Etc. Etc.

4. Another comparison comment:

Serialization: Also known as streaming. It is the process of laying out a data structure in a series of bits. Here, we’re not concerned about how/whether the data gets written out to the disk, but are rather concerned with the order in which things will get laid out, and how they should be “de-serialized”. For example, a Point object might get laid out as three co-ordinates: m_x, m_y and m_z (all floats). Serialization doesn’t really care if they are finally written out to the disk straight as 12 bytes total, or are written out as XML. It is only concerned with the order. During serialization, the Save and Load functions of the objects usually get called. The serialization mechanism can also used for cloning, or to issue RPCs, such as in SOAP.

Persistence: Also known as archiving (as in BOOST). It is the process of actually writing (or reading) the streamed data to disk. This process deals more with “how” the data gets converted to bytes. For example, writing to an IStorage would be provided by a different persistence engine than writing to an ADP file. Similarly, writing to an XML or simple ASCII is dictated by the particular persistence mechanism used.

转载于:https://www.cnblogs.com/taoxu0903/archive/2011/01/07/1929932.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值