gpt4 book ai didi

Cygwin/Cygserver 共享内存

转载 作者:行者123 更新时间:2023-11-30 16:42:28 27 4
gpt4 key购买 nike

我试图将一些共享内存代码从 CENTOS(3.5) 迁移到 CYGWIN(2.8.1, win10)。共享内存通常是这样工作的:

  1. 通过 shmget 在进程中生成共享内存。

  2. 通过shmat映射该进程上的共享内存并记录位置,然后将一些信息填充到内存中。

  3. 通过“shmat”将共享内存映射到另一个进程,传递最后记录的进程的位置,因为我们期望两个进程将共享内存映射到相同的地址。

下面是一些代码来解释:

// one process
size_t size = 1024 * 1024;//1M
int id = shmget(IPC_PRIVATE, size, 0660);
char *madr = 0;
char *location = shmat(id, madr, 0);

// another process
char *location1 = shmat(id, location , 0);
// !!!we hope location1 and location should be the same!!!

在 Centos 上它运行良好。

在 Cygwin 上,一个进程将共享内存映射到 0xffd90000,另一个进程与之不同,但映射到 oxffdb0000。我们检查内存 0xffd90000 在该进程上是否可用。

最佳答案

对 Linux 的期望也是错误的,请参阅
https://linux.die.net/man/2/shmat

Be aware that the shared memory segment attached in this way may be attached at different addresses in different processes. Therefore, any pointers maintained within the shared memory must be made relative (typically to the starting address of the segment), rather than absolute.

关于Cygwin/Cygserver 共享内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45788744/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com