C# Very Large String Manipulation (Out of Memory Exception)

后端 未结 5 1036
别跟我提以往
别跟我提以往 2021-01-17 10:32

I have a need to read in a 1gb raw text file from disk to ram to do some string manipulation in C#.

string contents = File.ReadAllText(path)
<
5条回答
  •  一个人的身影
    2021-01-17 11:33

    If you REALLY want to do this huge string manipulation in memory then you are NOT out of luck anymore, provided you can meet the following requirements

    1. Compile targeting x64
    2. Run in a x64 system
    3. Target .NET 4.5

    This will lift all the memory limitations you're facing. Your process memory will be limited only by your computer memory, and there is not a 2GiB limit on a single .NET object starting in .NET 4.5 for x64.

提交回复
热议问题