创建一个DLL共享两个进程之间的内存 [英] Create a DLL to share memory between two processes
问题描述
我需要使用DLL的运作类似于Linux的共享内存。我很少有Windows编程的经验,但我认为这是可能实现我的目标。我想这样类似下面的内容:
I need to use DLL's to function similar to Linux Shared Memory. I have very little Windows programming experience, but I think it is possible to accomplish my goal. I want to so something similar to below:
DLL
int x;
void write(int temp)
{
x = temp
}
int read()
{
return x;
}
过程1:
LoadDLL();
write(5); //int x = 5 now
2方法:
LoadDLL();
printf(read()); //prints 5 since int x = 5 from Proccess 1
当然这个例子忽略了比赛条件等,但有一个简单的方法去了解这样的事情?
Naturally this example neglects race conditions and the like, but is there a simple way to go about something like this?
我将使用Microsoft Visual Studio 10以创建DLL。可能有人解释我是怎么写的东西这个简单而其打造成为可以加载并呼吁类似伪code以上?
I would be using Microsoft Visual Studio 10 to create the DLL. Could someone explain how I would write something this simple and build it into a DLL that can be loaded and called similar to the pseudo-code above?
修改:因为我创造的过程是在LabVIEW和Lua不支持上述共享内存段和内存映射文件不能使用。他们这样做,但是,支持的DLL这就是为什么我需要这个过时的方法。
EDIT: Shared memory segments and Memory Mapped Files cannot be used because the processes I am creating are in LabVIEW and Lua which do not support the above. They do, however, support DLLs which is why I need this "outdated" approach.
推荐答案
默认情况下,使用DLL的每个进程都有自己的所有DLL全局和静态变量的实例。
By default, each process using a DLL has its own instance of all the DLLs global and static variables.
请参阅这里。
这篇关于创建一个DLL共享两个进程之间的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!