内存映射 - 我们可以在创建同一文件的多个内存视图时使用重复句柄吗? [英] Memory Map - Can we use duplicate handles while creating multiple memory views of the same file?

查看:115
本文介绍了内存映射 - 我们可以在创建同一文件的多个内存视图时使用重复句柄吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi All

我们的用例是在一个进程中创建同一文件的多个内存映射,并同时从这些视图中读取数据。我是否可以为每个视图创建使用重复句柄而不是新文件句柄。 

Our use case is to create the multiple memory maps of the same file in a single process and read the data from these views concurrently. Can i use duplicate handles instead of a new file handles for each view creation. 

重复句柄是否支持并发读取,就像本用例中的新句柄一样明智。

Will duplicate handles supports the concurrent reading like wise the new handles in this use case.

请回复。提前致谢

推荐答案

Hi Sukumar,

Hi Sukumar,

感谢您的合作。

>>"我是否可以为每个视图创建使用重复的句柄而不是新的文件句柄 "

据我所知,通常,两个进程共享内存映射文件,他们必须能够通过名称识别它。一个例外是子进程,它可以继承父进程的句柄。 Windows中的大多数对象可以明确地以
为目标进行继承。

As far as I know that ordinarily, for two processes to share a memory-mapped file, they must both be able to identify it by name. An exception to this is child processes, which can inherit their parent's handles. Most objects in Windows can be explicitly targeted for inheritance or not.

从字面上看,这意味着子进程可以通过提供与父对象相同的句柄值来访问对象。传达对子进程的处理是另一个问题。毕竟,子进程仍然是另一个进程,拥有自己的地址
空格,因此句柄变量本身不可转移。

Literally, this means the child process can access the object by supplying the same handle value as the parent. Communicating that handle to the child process is another concern. The child process is still another process after all, having its own address space, so the handle variable itself is not transferable.

此外, DuplicateHandle 提供了一个函数来提供更多控制,以便何时可以继承句柄。此函数可用于创建原始的重复句柄,并可用于更改
句柄的继承状态。在将句柄传递给子进程之前,应用程序可以调用此函数将MMF对象句柄状态更改为可继承。

Further, the DuplicateHandle function is provided to offer more control as to when handles can be inherited and not. This function can be used to create a duplicate handle of the original and can be used to change the inheritance state of the handle. An application can invoke this function to change an MMF object handle state to inheritable before passing the handle along to a child process.

因此您可以尝试使用 DuplicateHandle 功能。

So you can try to use the DuplicateHandle function.

最好的问候,

Hart


这篇关于内存映射 - 我们可以在创建同一文件的多个内存视图时使用重复句柄吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆