是否可以与另一个进程共享现有的一块RAM? [英] Is it possible to share an existing chunk of RAM with another process?

查看:212
本文介绍了是否可以与另一个进程共享现有的一块RAM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的32位应用程序,它有一个相当大的内存块(> 128 MB)(通过malloc / new分配)图像数据(多帧值)。通过SDK-API调用,应用程序的插件可以访问这个RAM块的开头的只读指针(const char *)。其他API调用可用于检索元数据,如宽度/高度/位深度等。我在SDK-API调用之外没有/很少控制这个应用程序。

I have an existing 32 bit application which has a rather big chunk of RAM (>128 MB) allocated (via malloc/new) and populated with some image data (multiple frames worth). A read only pointer (const char *) to the start of this chunk of RAM is accessible to the application's plugins via a SDK-API call. Other API calls are available to retrieve the meta data such as width/height/bit depth and so on. I have no/little control over this application outside the SDK-API calls.

我还有另一个64位应用程序(在我的控制下),它需要上述数据作为输入并且由于上采样/ 3D体积重建需要显着更多的RAM,这保证64位过程。

I have yet another 64 bit application (under my control) which requires the above data as input and requires significantly more RAM due to up sampling/3D volume reconstruction which warrants the 64 bit process.

我希望在32位进程中共享映射到这个现有指针的物理内存(它最初不是通过调用创建的,例如CreateFileMapping / MapViewOfFile,但通过malloc / new操作符调用)。

I wish to share the physical memory mapped to this existing pointer in the 32 bit process (which was not originally created via calls such as CreateFileMapping/MapViewOfFile but through malloc/new operator calls) with the 64 bit process.

是否可能?

通常我会在32位进程中创建一个大小相同的共享内存,复制内容并使用一些同步方法来发送数据。然而,在我的情况下,32位进程也拥挤着许多插件,因此它非常接近可用的自由虚拟空间的限制。有一个机会MapViewOfFile可能会失败,因为内存碎片。因为我只需要只读副本的大块的RAM,我试图避免额外的分配和复制。

Typically I'd create a same sized shared memory in the 32 bit process, copy the contents over and use some synchronization method to signal the data is available. In my case however, the 32 bit process is also getting crowded with many plugins and therefore it is very near the limits of available free virtual space. There is a chance MapViewOfFile might fail because of the memory fragmentation. Since I only need a read only copy of the chunk of RAM, I was trying avoid additional allocation and copying.

我的目标是64位Windows 7,Visual C ++ 2010 / 2015

I am targeting 64 Bit Windows 7, Visual C++ 2010/2015

推荐答案

否。首先,共享内存实际上是共享页面。您的 malloc 调用绝不保证返回页面对齐的内存。此外,这些共享页面必须在虚拟地址空间的空闲区域中创建,但 malloc ed内存由已分配和未共享页面支持。

No. For starters, "shared memory" are actually shared pages. Your malloc call is by no means guaranteed to return page-aligned memory. Furthermore, those shared pages must be created in a free region of your virtual address space, but malloced memory is backed by allocated and unshared pages.

这篇关于是否可以与另一个进程共享现有的一块RAM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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