大家好,又见面了,我是你们的朋友全栈君。创建文件内存映射:
HANDLE hMySharedMapFile=CreateFileMapping((HANDLE)0xFFFFFFFF),
NULL,PAGE_READWRITE,0,0x1000,”MySharedMem”);
其中第一个参数文件句柄设置成0XFFFFFFFF代表什么意思呢?
0XFFFFFFFF在内存中又是什么意思呢?
为什么要把文件句柄设置成0XFFFFFFFF???
网友回复:句柄设置成0XFFFFFFFF表示在内存中开辟一块区域。
网友回复:就是在内存中建立,而不是使用盘上的某个文件啊
网友回复:内存映射API函数CreateFileMapping创建一个有名的共享内存:
HANDLE CreateFileMapping(
HANDLE hFile, // 映射文件的句柄,
//设为0xFFFFFFFF以创建一个进程间共享的对象
LPSECURITY_ATTRIBUTES lpFileMappingAttributes, // 安全属性
DWORD flProtect, // 保护方式
DWORD dwMaximumSizeHigh, //对象的大小
DWORD dwMaximumSizeLow,
LPCTSTR lpName // 必须为映射文件命名
);
网友回复: 要把文件映像到内存,首先必须调用CreateFileMapping()函数,它需要用一个由CreateFile()函数打开并返回的文件句柄,对大多数共享内存应用程序,必须把此句柄设置为0xFFFFFFFF,用来指定系统页面文件。通过使用上面的特殊句柄,可以不调用CreateFile函数,当然在完成时,也不必有一个内存的磁盘文件拷贝。
网友回复:0XFFFFFFFF是INVALID_HANDLE_VALUE,表示不指定文件,在系统分页文件(pagefile.sys)中分配映射的磁盘空间。
网友回复:If hFile is (HANDLE)0xFFFFFFFF, the calling process must also specify a mapping object size in the dwMaximumSizeHigh and dwMaximumSizeLow parameters. The function creates a file-mapping object of the specified size backed by the operating-system paging file rather than by a named file in the file system. The file-mapping object can be shared through duplication, through inheritance, or by name.
网友回复:MSDN:
If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a size for the file mapping object in the dwMaximumSizeHigh and dwMaximumSizeLow parameters. In this scenario, CreateFileMapping creates a file mapping object of a specified size that is backed by the system paging file instead of by a file in the file system.
INVALID_HANDLE_VALUE就是-1即0xffffffff
网友回复:实际上是用于进程间通信的,以共享内存的方式。
网友回复:-1
hFile
Handle to the file from which to create a mapping object. The file must be opened with an access mode compatible with the protection flags specified by the flProtect parameter. It is recommended, though not required, that files you intend to map be opened for exclusive access.
If hFile is (HANDLE)0xFFFFFFFF, the calling process must also specify a mapping object size in the dwMaximumSizeHigh and dwMaximumSizeLow parameters. The function creates a file-mapping object of the specified size backed by the operating-system paging file rather than by a named file in the file system. The file-mapping object can be shared through duplication, through inheritance, or by name.
本篇文章来源于 IT者 | www.itzhe.cn 原文链接:http://itzhe.cn/news/20080923/231975.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/145837.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...