Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中处理大列表时OutOfMemoryException#_C#_List_File - Fatal编程技术网

C# 在C中处理大列表时OutOfMemoryException#

C# 在C中处理大列表时OutOfMemoryException#,c#,list,file,C#,List,File,我必须处理一些大的表格数据文件(例如:300.000行200列),为每个单元格创建一个数据结构 然而,在几千次迭代中,会抛出System.OutOfMemoryException(计算机有8GB RAM) 在我的例子中,我将每一行解析为一个字典列表,因为我必须拥有列名和值,并通过使用这些信息创建一个节点来处理它 代码如下: // foreach record foreach (Dictionary<string, string> inst in c.TodasInstancias)

我必须处理一些大的表格数据文件(例如:300.000行200列),为每个单元格创建一个数据结构

然而,在几千次迭代中,会抛出System.OutOfMemoryException(计算机有8GB RAM)

在我的例子中,我将每一行解析为一个字典列表,因为我必须拥有列名和值,并通过使用这些信息创建一个节点来处理它

代码如下:

// foreach record 
foreach (Dictionary<string, string> inst in c.TodasInstancias)
{
instance = null;
tmp = null;

// for each column
foreach (KeyValuePair<string, string> kv in inst)
{
    if ((tmp = this.Relations.Find(new Predicate<Relacionamento>(x => x.Target.Name == kv.Key))) != null)
   { // if this class has a relationship with other classes
       p = og.CreateUriNode(this.UriOntologiaPrefix + ":" + kv.Key);
       o = og.CreateUriNode(new Uri(tmp.CampoOrigem.Classe.Configs.Name_space + "/" + kv.Value));
       og.Assert(instancia, p, o);
   }
   else (kv.Key != c.Configs.Identificador)
   { // se for um campo comum de dados
       p = og.CreateUriNode(this.UriOntologiaPrefix + ":" + kv.Key);
       o = og.CreateLiteralNode(kv.Value);
       og.Assert(instancia, p, o);
   }
}
}
//foreach记录
foreach(c.todasisnstance中的词典安装)
{
实例=null;
tmp=null;
//每列
foreach(仪表中的键值对kv)
{
if((tmp=this.Relations.Find(新谓词(x=>x.Target.Name==kv.Key))!=null)
{//如果该类与其他类有关系
p=og.CreateUriNode(this.UriOntologiaPrefix+”:“+kv.Key);
o=og.CreateUriNode(新Uri(tmp.CampoOrigem.Classe.Configs.Name_space+“/”+kv.Value));
断言(实例,p,o);
}
else(千伏键!=c.Configs.Identificator)
{//se代表达多斯广场
p=og.CreateUriNode(this.UriOntologiaPrefix+”:“+kv.Key);
o=og.CreateLiteralNode(千伏值);
断言(实例,p,o);
}
}
}

关于如何绕过此异常的任何提示?

使用queryable处理大列表。 您可以检索一批记录,而不是使用Skip and Take检索所需的所有数据。 这样,您每次都将在内存中处理一个小列表。 例:

var count=context.entities.count();

对于(i=0,i您的内存不足,因此您无法绕过它。您的计算机无法继续运行,因为它需要内存。您需要找到一种更有效的方法来处理数据,即算法、数据结构、文件类型、语言等。每行都是一个
列表
?不要创建中间结构直接从一行到另一行l节点。Elijah是正确的,您只有这么多的进程内存。请研究从外部源流式传输此数据,而不是立即将整个数据集加载到内存中。@ElijahTate是的,这就是我的意思。是否有其他更有效的形式来处理数据的建议。@n关于如何从文件而不是l流式传输数据的示例马上装?
   var count=context.entities.Count(); 

   for(i=0,i<count,i+=1000)//1000 can be any size of batch
   {
       var batch =context.entities.Skip(i).Take(1000);
       //Do Operations you need
   }