开发者

System.OutOfMemoryException When trying to read 2.09 GB text file

开发者 https://www.devze.com 2023-03-13 03:26 出处:网络
System.OutOfMemoryException When trying to read 2.09 GB text file I am trying to read a txt file which consists of millions of lines. I am using this method.

System.OutOfMemoryException When trying to read 2.09 GB text file

I am trying to read a txt file which consists of millions of lines. I am using this method.

string[] srLines= File.ReadAllLines开发者_StackOverflow中文版("my_file.txt");

I have 16 GB DDR3 RAM memory. What is the solution? Thank you.

I am using Microsoft Visual Studio 2010 and Windows 7 64-bit.


Have you set your target to be 64bit as well?

In all cases .NET processes have a limit of memory allocatable per object (see http://blogs.msdn.com/b/joshwil/archive/2005/08/10/450202.aspx), I am not sure if that changed with .NET 4.0


I had the same problem on my 64Bit machine in VS2012. I changed "project settings" --> "Build" --> Uncheck "Prefer 32-bit" Now it works fine.


Unless you have a reason that you really need to have all those lines in memory all at once, you could also use a StreamReader and read the file sequentially. Your algorithm might be more complex but you will use much less memory.

0

精彩评论

暂无评论...
验证码 换一张
取 消