BinaryFormatter 是否应用任何压缩?
当 .NET 的 BinaryFormatter
用于序列化对象图,是否应用了任何类型的压缩?
我问是否应该担心对象图有许多重复的字符串和整数。
编辑 - 等等,如果字符串驻留在.NET中,就不需要担心重复的字符串,对吧?
When .NET's BinaryFormatter
is used to serialize an object graph, is any type of compression applied?
I ask in the context of whether I should worry about the object graph having many repeated strings and integers.
Edit - Hold on, if strings are interned in .NET, there's no need to worry about repeated strings, right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,它不提供任何压缩,但您可以使用
GZipStream
类型。编辑: Mehrdad 在他对 如何使用 gzip 压缩 .net 对象实例。
编辑 2: 字符串可以被保留,但这并不意味着每个字符串都被保留。我不会对 CLR 如何或为何决定实习字符串做出任何假设,因为这可能会随着版本的不同而改变(并且已经改变)。
No, it doesn't provide any compression but you can compress the output yourself using the
GZipStream
type.Edit: Mehrdad has a wonderful example of this technique in his answer to How to compress a .net object instance using gzip.
Edit 2: Strings can be interned but that doesn't mean that every string is interned. I wouldn't make any assumptions on how or why the CLR decides to intern strings as this can change (and has changed) from version to version.
不,它没有,但是......
我今天刚刚为我的应用程序添加了 GZipStream 支持,所以我可以在这里分享一些代码;
序列化:
反序列化:
注意:如果您使用 CryptoStream,以这种方式链接(解开)压缩和(解密)加密非常重要,因为您需要在加密从数据中产生噪音之前丢失熵。
No, it does not, but...
I just added GZipStream support for my app today, so I can share some code here;
Serialization:
Deserialization:
NOTE: if you use CryptoStream, it is kinda important that you chain (un)zipping and (de)crypting right this way, because you'll want to lose your entropy BEFORE encryption creates noise from your data.