private void read_file_seq(string path, BackgroundWorker worker) { byte[] buffer = new byte[1024 * 1024 * 16]; //16M SafeFileHandle handle = WinApiFunctions.CreateFile(path, FileAccess.Read, FileShare.None, IntPtr.Zero, FileMode.Open, this._fileFlags, IntPtr.Zero); if (handle.IsInvalid) { throw new IOException("Could not open file stream.", new Win32Exception()); } //缓冲区大小64M FileStream stream = new FileStream(handle, FileAccess.Read, 1024 * 1024 * 64, false); for (long i = 0L; i < Testsize; i += 1L) { stream.Read(buffer, 0, buffer.Length); } stream.Close(); }
private void write_file_seq(string path, BackgroundWorker worker) { new FileInfo(path).Delete(); SafeFileHandle handle = WinApiFunctions.CreateFile(path, FileAccess.ReadWrite, FileShare.None, IntPtr.Zero, FileMode.CreateNew, this._fileFlags, IntPtr.Zero); if (handle.IsInvalid) { throw new IOException("Could not open file stream.", new Win32Exception()); } //FileStream 缓冲区大小1024*1024*16 16M FileStream stream = new FileStream(handle, FileAccess.ReadWrite, 1024 * 1024 * 16, false); for (long i = 0L; i < Testsize; i += 1L) { stream.Write(this.rnd_array, 0, rnd_array.Length); } stream.Flush(); stream.Close(); }