本文目录
- OpenFileMapping和CreateFileMapping有什么区别
- C#中CreateFileMapping,MapViewOfFile怎么用
- CreateFileMapping 大文件拷贝问题
- C#跟C++通过CreateFileMapping共享结构体数据怎么实现
OpenFileMapping和CreateFileMapping有什么区别
句柄本质上是一个unsigned long类型,三十二位无符号整数,指向指针的指针。每个进程都有一个表来维护一组句柄,句柄是私有的,所以每个进程的句柄一般不一样,但是句柄指向的内容可以是相同的。
C#中CreateFileMapping,MapViewOfFile怎么用
public static extern IntPtr CreateFileMapping( IntPtr hFile, IntPtr lpFileMappingAttributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName); public enum FileMapProtection : uint { PageReadonly = 0x02, PageReadWrite = 0x04, PageWriteCopy = 0x08, PageExecuteRead = 0x20, PageExecuteReadWrite = 0x40, SectionCommit = 0x8000000, SectionImage = 0x1000000, SectionNoCache = 0x10000000, SectionReserve = 0x4000000, } public static extern IntPtr MapViewOfFile( IntPtr hFileMappingObject, FileMapAccess dwDesiredAccess, UInt32 dwFileOffsetHigh, UInt32 dwFileOffsetLow, UIntPtr dwNumberOfBytesToMap); public enum FileMapAccess : uint { FileMapCopy = 0x0001, FileMapWrite = 0x0002, FileMapRead = 0x0004, FileMapAllAccess = 0x001f, FileMapExecute = 0x0020, }
using System.Runtime.InteropServices;
CreateFileMapping 大文件拷贝问题
函数CreateFileMapping()第四个参数指定了创建的文件映射对象的字节大小,该参数类型为DWORD,也就是说文件映射对象的尺寸最大为2147483648字节,即2G。文件大小确实与和虚拟内存有关,毕竟是需要在进程内部开辟与文件大小相同的内存空间的。如果要大于2G的文件,那么不能使用文件映射对象的方法,可以使用简单的复制文件方法,如从源文件依次读取N个字节,并依次写入目的文件。
C#跟C++通过CreateFileMapping共享结构体数据怎么实现
C# 使用 CreateFileMapping API,至于C++怎么用就别问我了
public static extern IntPtr CreateFileMapping( IntPtr hFile, IntPtr lpFileMappingAttributes, FileMapProtection flProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, string lpName);enum FileMapProtection : uint{ PageReadonly = 0x02, PageReadWrite = 0x04, PageWriteCopy = 0x08, PageExecuteRead = 0x20, PageExecuteReadWrite = 0x40, SectionCommit = 0x8000000, SectionImage = 0x1000000, SectionNoCache = 0x10000000, SectionReserve = 0x4000000,}
OpenFileMapping API 的使用
static extern IntPtr OpenFileMapping( uint dwDesiredAccess, bool bInheritHandle, string lpName);