内存异常在C# [英] Memory exception in C#

查看:154
本文介绍了内存异常在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/9649722/how-to-refer-to-children-in-a-tree-with-millions-of-nodes">How是指儿童在树上数以百万计的节点

我想实现一棵树将举行数以百万计的节点,这反过来又可以有子节点数目不详。

I'm trying to implement a tree which will hold millions of nodes, which in turn can have an unspecified number of children nodes.

要实现这一点(因为每个节点都可以有一个以上的子节点),我存储一个字典数据结构中的一个节点的孩子。由于这一结果,当每个对象节点被创建(下数以百万计),我有其中包含存储在各节点的字符值的节点对象,藏汉作为一个单独的字典结构,其保持参考子节点

To achieve this (since each node can have more than one child node), I'm storing a node's children within a Dictionary data structure. As a result of this, when each object node is created (out of millions), I've got a node object which contains a character value stored in the respective node, aswell as a separate Dictionary structure which holds a reference to the children nodes.

我的树的作品几千个节点,然而,当它达到数以百万计的节点,一个内存溢出异常发生。这是由于事实的数百万运行在内存还节点中的每一个都有自己的意思?即我已经得到了数百万个对象运行?

My tree works for a few thousand nodes, however when it reaches millions of nodes, an out of memory exception occurs. Is this due to the fact that each one of the millions of nodes running in memory also has its own Dictionary? i.e. I've got millions of objects running?

我需要有在内存中运行这些对象,并且不能使用的文件或数据库。任何人都可以提出一个解决方案吗?

I need to have these objects running in memory, and cannot use files or databases. Could anyone suggest a solution?

推荐答案

您OOM异常可能是由于蕙碎片,而不是实际运行内存。你可以尝试切换到SortedDictionary,它采用了红黑树,而不是字典,它使用一个哈希表,看看是否可以改善的问题。或者你也可以实现自己的树形结构。

Your OOM exception may be due to LOH fragmentation, rather than actually running out of memory. You could try switching to SortedDictionary, which uses a red-black tree, rather than Dictionary, which uses a hashtable, and see if that improves matters. Or you could implement your own tree structure.

这篇关于内存异常在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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