English 中文(简体)
面对序列化问题
原标题:Facing problem with serialization
  • 时间:2010-03-04 14:16:03
  •  标签:
  • c#

HI Here is my scenario where i have to serialize an object to a file.

我正在使用BinaryFormatter将一个对象序列化为,

            IFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream1, object);

我正在按照以下方式编写GetObjectData()函数,

            serinfo.AddValue("string1",objecta);
            serinfo.AddValue("string2",objectb);
            serinfo.AddValue("string3",objectc);

我正在对 objectb 中的 list1 和 list2 进行序列化。这些列表的大小每次都会有所不同(每个列表也可能有 100000 个元素..这意味着列表中的元素数量影响流的大小)。因此,当我对对象进行序列化时,我的流大小不应超过 10mb,如果它超过了,我应该写入另一个流。简而言之,如果大小超过了 10mb,我应该有一个以上的流,并且每个流应该采用以下格式。

stream1 --> objecta,(objectb)some n values in list,objectc
stream2 --> objecta,(objectb)values in list from n+1 to some m,objectc
 ..
streamn --> ........

每个流的大小应限制在10MB以内。

Please provide me some clues to do this.. thanks in advance.. (first of all thanks for reading this large qn..:P)

问题回答

我想将我的对象序列化到MemoryStream中,然后检查将其添加到当前的FileStream中是否会超过10MB,如果会,就在写入之前开始一个新的流。

我建议您将流的拆分与序列化分开。也就是说,将其序列化为一个流(无论长度需要多长),然后单独将该流分成10Mb的块。

您可以直接这样做,因为只有一流才能通过<条码>。 无论是使用<代码>MemoryStream,作为目标,然后人工传播到溪流,或在序列化之前将初步物体分解成碎片





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签