简体   繁体   English

XML序列化:64位Windows7,oct处理器内核,32GB RAM和OutOfMemory异常

[英]XML serialization: 64Bit Windows7, oct processor cored, 32GB RAM and OutOfMemory exception

While processing 500 MB data and trying to serialize it, 处理500 MB数据并尝试序列化时,

GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)

throws System.OutOfMemoryException 抛出System.OutOfMemoryException

XML Serializer: XML Serializer:

StringWriter xmlStr = new StringWriter();

XmlTextWriter twa = new XmlTextWriter(xmlStr);

lock(myLock)
{
    mySerializer.WriteObject(twa, myHandlerMap); // OutOfMemoryException

    twa.Flush();
    twa.Close();

    set.StringBuffer = xmlStr.ToString();

    xmlStr.Dispose()
}

After reading the last paragraph at following link: http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/10/10/stringbuilder-outofmemoryexception.aspx 阅读以下链接的最后一段后: http//blogs.msdn.com/b/vsofficedeveloper/archive/2008/10/10/stringbuilder-outofmemoryexception.aspx

I doubt if it is possible to solve this issue without MS fixing it? 我怀疑如果没有MS修复它是否有可能解决这个问题?

Exception Trace: 异常跟踪:

RemoteStackTrace:    
   at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)
   at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength)
   at System.Text.StringBuilder.Append(Char value)
   at System.IO.StringWriter.Write(Char value)
   at System.Xml.XmlTextWriter.InternalWriteEndElement(Boolean longFormat)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.WriteString(XmlWriterDelegator xmlWriter, String value, XmlDictionaryString name, XmlDictionaryString ns)
   at WriteKeyValueOfstringstringToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )
   at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
   at WriteArrayOfKeyValueOfstringstringToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , CollectionDataContract )
   at System.Runtime.Serialization.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiType(XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerializeWithSurrogate(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
   at WriteGenericViewingMPStateToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )
   at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiType(XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerializeWithSurrogate(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteSerializationInfo(XmlWriterDelegator xmlWriter, Type objType, SerializationInfo serInfo)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteISerializable(XmlWriterDelegator xmlWriter, ISerializable obj)
   at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerializeWithSurrogate(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
   at WriteKeyValueOfstringStateSerializeSetjJgp3TWnToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )
   at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
   at WriteArrayOfKeyValueOfstringStateSerializeSetjJgp3TWnToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , CollectionDataContract )
   at System.Runtime.Serialization.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
   at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)
   at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)
   at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)

Pls. PLS。 let me know how can it be solved? 让我知道它怎么解决?

500MB is pretty big for xml, and it would not surprise me to hear that it isn't happy. 对于xml来说500MB是相当大的,听到它不开心并不会让我感到惊讶。 If possible, I would look at something streaming -based, ie XmlWriter / XmlReader . 如果可能的话,我会看一些基于的东西,即XmlWriter / XmlReader Without more detail it isn't clear whether that is possible here. 没有更多细节,目前尚不清楚这是否可行。 Alternatively, consider another format! 或者,考虑另一种格式! Seriously... xml doesn't play nicely at big sizes. 说真的...... xml不适合大尺寸。

The first thing to try, though, is... don't use a string (or StringBuilder); 不过,首先要尝试的是...... 不要使用字符串 (或StringBuilder); but instead, read/write directly from/to disk via a FileStream over an XmlReader / XmlWriter . 但是,通过XmlReader / XmlWriter上的FileStream直接从/向磁盘读/写。

I would prefer serializing this directly into a file. 我更希望将其直接序列化为文件。 500 MB is a quite a huge data and will getting much more when serializing it in "chatty" xml. 500 MB是一个非常庞大的数据,并且在使用“chatty”xml进行序列化时会获得更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当对2 GB XML文件SignedXml.ComputeSignature进行签名时,在具有8 GB RAM的64位窗口中抛出内存不足异常 - When signing 2 GB XML file SignedXml.ComputeSignature throwing out of memory exception in 64 bit windows with 8 GB RAM LinqToExcel在Windows7 64位上,办公室64位 - LinqToExcel on Windows7 64 bit with office 64bit 无法在Windows7 64bit中为MSAceess打开O​​DBC连接 - Can not Open ODBC connection for MSAceess in Windows7 64bit 无法在Windows 7 64bit中连接套接字 - Trouble getting sockets to connect in windows7 64bit WbitQueryUserToken在32位Windows(64位工作)之后“Win32Exception:操作成功完成” - “Win32Exception: The operation completed successfully” after WTSQueryUserToken on 32bit Windows (64bit works) 检查服务是否在 Windows 上安装为 64 位或 32 位 - Check if service is installed as 64bit or 32bit on Windows Windows应用商店DLL 32位和64位 - Windows Store App DLL 32bit and 64bit 在32位Windows 7操作系统中构建64位应用程序 - Build 64bit application in 32bit windows 7 OS 32位和64位Windows之间的日期时间粒度 - Datetime Granularity between 32bit and 64bit Windows 如何确定处理器是否在32位操作系统上支持64位 - How to determine if processor supports 64bit on a 32bit OS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM