現在的位置: 首頁 > 綜合 > 正文

Persistence VS Serialization

2013年05月09日 ⁄ 綜合 ⁄ 共 2286字 ⁄ 字號 評論關閉
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.

抱歉!評論已關閉.