加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

为什么.net通用字典如此之大

发布时间:2020-12-17 00:21:55 所属栏目:大数据 来源:网络整理
导读:我在VB.net中序列化一个通用字典,我很惊讶它是一个单项的大约1.3kb.我做错了什么,还是我应该做的其他事情?我有大量的词典,它正在杀死我把它们全部发送到网上.我用于序列化的代码是 Dim dictionary As New Dictionary(Of Integer,Integer) Dim stream As New
我在VB.net中序列化一个通用字典,我很惊讶它是一个单项的大约1.3kb.我做错了什么,还是我应该做的其他事情?我有大量的词典,它正在杀死我把它们全部发送到网上.我用于序列化的代码是
Dim dictionary As New Dictionary(Of Integer,Integer)
    Dim stream As New MemoryStream
    Dim bformatter As New BinaryFormatter()

    dictionary.Add(1,1)

    bformatter.Serialize(stream,dictionary)

    Dim len As Long = stream.Length
字典的默认序列化必须包括字典类型的类型信息,使用的比较器以及每个项目的类型(键和值),因为它们通常可能是子类型.必须为每个字典添加此开销.如果将数据打印为字符串,则可以看到有许多完全限定类型占用了大量字节:

?????System.Collections.Generic.Dictionary2[[System.Int32,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089],[System.Int32,PublicKeyToken=b77a5c561934e089]]aVersionbComparerbHashSizerKeyValuePairsb?System.Collections.Generic.GenericEqualityComparer1[[System.Int32,PublicKeyToken=b77a5c561934e089]]b?System.Collections.Generic.KeyValuePair2[[System.Int32,PublicKeyToken=b77a5c561934e089]][]tt?System.Collections.Generic.GenericEqualityComparer1[[System.Int32,PublicKeyToken=b77a5c561934e089]]a?System.Collections.Generic.KeyValuePair2[[System.Int32,PublicKeyToken=b77a5c561934e089]]?????System.Collections.Generic.KeyValuePair2[[System.Int32,PublicKeyToken=b77a5c561934e089]]keyvaluebbv

您可能更喜欢使用自定义格式进行序列化,或者使用稍微轻一些的标准格式,例如JSON.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读