【200分】求C# 内存映射文件的代码

来源:百度知道 编辑:UC知道 时间:2024/05/09 04:02:14
我需要做一个查询数据库的小工具,数据库文件有很多,有好几个G,是按天生成的数据。听说通过内存映射文件可以提高访问文件的速度。帮帮忙,谁有这方面的代码?给提供答案者200分。先给分可能会浪费,所以有答案了再给
急急急

谢谢,大侠,能稍作解释吗?!

using System.Runtime.InteropServices;

[DllImport("kernel32.dll")]
public static extern IntPtr CreateFileMapping(IntPtr hFile,
IntPtr lpFileMappingAttributes, uint flProtect,
uint dwMaximumSizeHigh,
uint dwMaximumSizeLow, string lpName);

[DllImport("kernel32.dll")]
public static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, uint
dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow,
IntPtr dwNumberOfBytesToMap);

[DllImport("kernel32.dll")]
public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);

[DllImport("kernel32.dll")]
public static extern bool CloseHandle(IntPtr hObject);

[DllImport("kernel32.dll")]
public static extern IntPtr CreateFile(string lpFileName,
int dwDesiredAccess, FileShare dwShareMode, IntPtr securityAttrs,
FileMode dwCreationDisposition, int dwFlags