[英]Is there any limits for binary serialization / deserialization object graph size in .net?
For example, i have: 例如,我有:
struct SomeStruct
{
//some fields
//each instance will store info read from file, maybe be 3kb, maybe more.
}
List<SomeStruct> lst = new List<SomeStruct>();
I will add to that list crazy amount of objects, so it will end up to 10Gbs or more in size. 我将在该列表中添加疯狂数量的对象,因此最终大小将达到10Gbs或更多。 Can i serialize lst without any errors like out of memory and etc? 我可以序列化lst而不出现内存不足等错误吗? Can i deserialize it later? 我可以稍后反序列化吗?
If you can hold the list of items in memory at one time, you should have a decent chance of serializing/deserializing them. 如果您可以一次将列表保存在内存中,则应该有很大的机会将它们序列化/反序列化。 You may want to handle them individually, in a stream, rather than serializing/deserializing the entire list all at once, perhaps. 您可能想在流中单独处理它们,而不是一次全部序列化/反序列化整个列表。 That would take care of any edge cases you might have. 这样可以解决您可能遇到的任何情况。
Pseudo-code: 伪代码:
private void SerializeObjects(List<foo> foos, Stream stream)
{
foreach (var f in foos)
{
stream.Write(f);
}
}
private void DeserializeObjects(List<foo> foos, Stream stream)
{
foo f = stream.ReadFoo();
while (f != null)
{
foos.Add(f);
f = stream.ReadFoo();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.