带有 Xml 文档的大型对象堆

发布于 2024-07-28 11:47:38 字数 582 浏览 1 评论 0原文

这可能与 .NET 集合和大对象堆 ( LOH)

在 .Net 中,我正在加载一个带有字符串的 XmlDocument,当 xml 转换为 base64 时,该字符串会生成大约 200KB 的文本文档。 重点是,字符串应该分配到大对象堆。 通过阅读此处的比较,我知道 XmlReader 是读取字符串的最有效方法,但 XmlDocument 可能为我提供了更直接的读取方式,具有更多功能(xpath)。

XML 的每个节点都应该是一个相当小的字符串,与大型对象堆相差甚远。 使用 Lutz .Net Reflector,XmlDocument 似乎在内部使用链接节点。

最后,我的问题是:在使用 XmlDocument 时,加载这个节省约 200 KB(> 85000 字节)的字符串是否会导致另一个对象出现在 LOH 中。 我们有点担心堆碎片并导致 OOM 错误。 或者 XmlDocument 是否恰好(至少对于我所询问的数据的情况)为托管堆创建了大量对象?

This is probably along the lines of .NET Collections and the Large Object Heap (LOH)

In .Net, I'm loading an XmlDocument with a string that makes ~200KB text document when the xml is converted to base64. The point being, the string should be allocated to the large object heap. I know from reading comparisons here that the XmlReader is the most efficient way to read the string, but the XmlDocument probably gives me the more straight forward read, with more functionality (xpath).

Each node of my XML should be a fairly small string, nothing near heading to the large object heap. Using Lutz .Net Reflector it appears the XmlDocument uses linked nodes internally.

So finally, my question: Will loading this string that saves ~200 KB (>85000 Bytes) cause yet another object to the LOH when using XmlDocument. We're a little worried about fragmenting the heap and leading to OOM errors. Or does the XmlDocument just happen to (at least for the case of data I'm asking about) create a lot of objects to the managed heap?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

¢好甜 2024-08-04 11:48:04

为什么首先要将 XML 加载到字符串中? 数据从哪里来? 您不能将其(例如 StreamTextReader)直接传递到 XmlDocument 中开始吗?

Why are you loading the XML into a string to start with? Where is the data coming from? Can't you pass that (e.g. a Stream or TextReader) directly into XmlDocument to start with?

财迷小姐 2024-08-04 11:47:58

只有大于 85 kB 的连续数据对象才会最终出现在大对象堆中。 例如,具有数万个元素的大型字符串和数组。

XmlDocument 由许多小对象组成,因此它很少在大对象堆上分配任何内容。 唯一的机会是节点包含数万个子节点,或者值超过 42500 个字符。

It's only object of continous data that is larger than 85 kB that ends up in the large objects heap. For example large strings and arrays with ten thousands of elements.

An XmlDocument consists of a lot of small objects, so it will very rarely allocate anything on the large objects heap. The only chance for that is if a node contains tens of thousande of children, or if a value is longer than 42500 characters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文