BinaryFormatter中的引用完整性 [英] Reference integrity in BinaryFormatter

查看:86
本文介绍了BinaryFormatter中的引用完整性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Protobuf-net中存在AsReference选项,并且BinaryFormatter是图形序列化程序"一词使我认为BinaryFormatter不维护引用,而是为每个对象进行了复制.

The existence of AsReference option in Protobuf-net and the word that BinaryFormatter is a "graph serializer" lead me to assume that BinaryFormatter does not maintain references and that it makes a copy of every object.

但是我做了一些测试,发现即使在递归引用中,单个BinaryFormatter Serialize()或Deserialize()调用中的所有引用也都得到了维护.

But I did some tests and found out that all references in a single BinaryFormatter Serialize() or Deserialize() call are maintained even for recursive referencing.

我可以确认BinaryFormatter确实维护引用吗?与Protobuf-net有何不同?好像我对图形序列化"的理解不正确?我还要注意什么?

Can I confirm that BinaryFormatter does indeed maintain references? How is this different from Protobuf-net? Seems like I understand "graph serialization" incorrectly? What else should I look out for?

谢谢.

推荐答案

tl; dr;版本-BinaryFormatter始终保留引用.

tl;dr; version - BinaryFormatter always preserves references.

BinaryFormatter是图形序列化器"的事实与它保留引用"同义,因为需要 才能精确地复制图形.替代方法是 tree 序列化程序(其中最多 XmlSerializerDataContractSerializer(未启用特定选项),JavascriptSerializer和不带AsReference的protobuf-net都是基于树的.树序列化器通常不会保留引用(除非它们起作用了一些技巧,即如果启用全图模式或Protobuf-net使用AsReference进行操作,则DataContractSerializer会做什么).树序列化器(未启用伏都教)倾向于与递归模型一起混乱,这使得它们很容易被发现.

The fact that BinaryFormatter is a "graph serializer" is synonymous with "it preserves references", since that is required to accurately reproduce a graph. The alternative is a tree serializer (which is most of them; XmlSerializer, DataContractSerializer (without a particular option enabled), JavascriptSerializer and protobuf-net without AsReference are all tree-based). Tree serializers do not generally preserve references (unless they work some tricks, i.e. what DataContractSerializer does if you enable full-graph mode, or protobuf-net does with AsReference). Tree serializers (without voodoo enabled) tend to explode in a mess with a recursive model, which makes them easy to spot.

这篇关于BinaryFormatter中的引用完整性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆