大于2GB的文件的System.IO.File.ReadAllBytes [英] System.IO.File.ReadAllBytes for file larger than 2GB

查看:596
本文介绍了大于2GB的文件的System.IO.File.ReadAllBytes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大文件,需要将其复制到内存中以进行进一步处理.该软件适用于小于2GB的文件,但是一旦超过此限制,我就会收到一个例外,即ReadAllBytes仅支持小于2GB的文件.

I have a large file that I need to copy to memory for further processing. The software works fine for files smaller than 2GB, but as soon as they pass this limit I get an exception that ReadAllBytes only supports files smaller than 2GB.

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

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

该进程已经是64位,并且标志 gcAllowVeryLargeObjects 已经设置.

The process is already 64bit and the flag gcAllowVeryLargeObjects is already set.

推荐答案

我怀疑您可以比内存映射文件

I doubt you can do anything faster than a memory mapped file 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来处理数据.

You can then use CreateViewAccessor or CreateViewStream to manipulate the data.

这篇关于大于2GB的文件的System.IO.File.ReadAllBytes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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