为什么我的新的XmlTextReader的(流)的阅读在很多兆字节到内存中,而不是流是否正常? [英] Why is my new XmlTextReader(stream) reading in many megabytes into memory rather than streaming properly?

查看:268
本文介绍了为什么我的新的XmlTextReader的(流)的阅读在很多兆字节到内存中,而不是流是否正常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XML流进一个XmlReader当越来越内存不足异常!展望在内存分析器,我们可以看到,它是通过调用StringBuilder.Append及以上导致吨128KB缓冲区填充所有的内存。

I am getting Out of Memory Exceptions when STREAMING in XML into an XmlReader! Looking in a memory profiler we can see that it is calling StringBuilder.Append over and over resulting in tons of 128KB buffers filling all of memory.

这是很违背了流。它不应该被加载多个4KB缓冲区。

That's pretty contrary to "streaming". It shouldn't be loading more than one 4KB buffer.

推荐答案

通过.NET源代码的阅读,它原来有一个确实会读遥遥领先,击败流的宗旨v1compat模式。那么,你如何避免让它变成愚蠢的模式?

Reading through the .NET source code, it turns out there's a "v1compat" mode that will indeed read way ahead, defeating the purpose of streaming. So, how do you avoid getting it into that stupid mode?

原来,有叫新的XmlTextReader的(流)之间的巨大差异XmlReader.Create (流),微软并没有刻意去记录......而我却总是随时随地在任何岗位找到...前将其放入v1compat模式!

It turns out that there's a HUGE difference between calling 'new XmlTextReader(stream)' and 'XmlReader.Create(stream)' that Microsoft didn't bother to document... and I could never find in any post anywhere... the former puts it into 'v1compat' mode!!!

的sooo,除非你需要你的XmlReader的行为完全像它确实在.NET 1.1中,包括流媒体不当行为,你永远也不会称之为新的XmlTextReader的(流)...而不是使用'XmlReader.Create(流)或者,如果你需要尝试匹配的XmlTextReader使用的设置(如果您没有通过XmlReaderSettings接受一个XmlReaderSettings一种变型,那么至少有些设置也有所不同......我不知道是什么设置将最佳匹配新的XmlTextReader......如果有人知道,请添加在这里!

Sooo, unless you need your XmlReader to behave exactly like it did in .NET 1.1, including improper streaming behavior, you should NEVER EVER call 'new XmlTextReader(stream)' ... instead use 'XmlReader.Create(stream)' or one of the variants that takes an XmlReaderSettings if you need to try to match the settings XmlTextReader used (if you don't pass an XmlReaderSettings, then at least some of the settings will be different... I am not sure what settings would best match 'new XmlTextReader'... if anybody knows, please add that here!

这篇关于为什么我的新的XmlTextReader的(流)的阅读在很多兆字节到内存中,而不是流是否正常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆