0
當我將超大字符串數據(100 Mb)保存到Xml時,我收到了一個非常奇怪的內存不足異常。我不確定。有沒有人有什麼想法發生了什麼?我僅限於使用2.0框架。XmlWriter OutOfMemoryException
Exception Stack:
System.OutOfMemoryException was unhandled
Message=Exception of type 'System.OutOfMemoryException' was thrown.
Source=mscorlib
StackTrace:
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Write(Char value)
at System.Xml.XmlTextWriter.InternalWriteEndElement(Boolean longFormat)
at System.Xml.XmlTextWriter.WriteEndElement()
at System.Xml.XmlWriter.WriteElementString(String localName, String ns, String
SampleCode:
StreamWriter streamWriter = new StreamWriter(stream);
XmlTextWriter textWriter = new XmlTextWriter(streamWriter);
XmlWriter writer = textWriter;
writer.WriteStartDocument(true);
你必須一次全部寫入100MB - 你能可能做到這一點在大塊? – dash
@dash:使用XmlWriter表示它是以塊寫入的。 –
@HenkHolterman我不是很清楚,但我的意思是原始字符串 - 而不是從內存中的字符串中寫出所有100MB的數據,加載一點,寫一點,加載一點,寫一點......到磁盤上的文件:-) – dash