我正在研究一个在大文件上进行大量读/写随机访问的程序(直到64 GB).文件是专门构建的,为了对它们进行访问,我创建了一个框架; 过了一会儿,我试着测试它的性能,我注意到在预分配的文件顺序写入操作太慢而不能接受.经过多次测试后,我在没有框架的情况下复制了行为(只有FileStream方法); 这是(使用我的硬件)复制问题的代码部分:
FileStream fs = new FileStream("test1.vhd", FileMode.Open);
byte[] buffer = new byte[256 * 1024];
Random rand = new Random();
rand.NextBytes(buffer);
DateTime start, end;
double ellapsed = 0.0;
long startPos, endPos;
BinaryReader br = new BinaryReader(fs);
br.ReadUInt32();
br.ReadUInt32();
for (int i = 0; i < 65536; i++)
br.ReadUInt16();
br = null;
startPos = 0; // 0
endPos = 4294967296; // 4GB
for (long index = startPos; index < endPos; index += buffer.Length)
{
start = DateTime.Now;
fs.Write(buffer, 0, …Run Code Online (Sandbox Code Playgroud)