大于2GB的文件的System.IO.File.ReadAllBytes

本文关键字:File ReadAllBytes IO 文件 2GB 大于 System | 更新日期: 2023-09-27 18:30:08

我有一个大文件需要复制到内存中进行进一步处理。该软件适用于小于2GB的文件,但一旦它们超过这个限制,我就会得到一个例外,ReadAllBytes只支持小于2GB。

byte[] buffer = System.IO.File.ReadAllBytes(file); // exception if file > 2GB

将大于2GB的文件复制到内存的最快方法是什么

进程已为64位,并且标志gcAllowVeryLargeObjects已设置。

大于2GB的文件的System.IO.File.ReadAllBytes

我怀疑你能比内存映射文件做得更快http://msdn.microsoft.com/en-us/library/system.io.memorymappedfiles.memorymappedfile(v=vs.110).aspx.

using ( var file = MemoryMappedFile.CreateFromFile( "F:''VeryLargeFile.data" ) )
{
}

然后可以使用CreateViewAccessor或CreateViewStream来处理数据。