映射已将内存分配到共享内存

时间:2015-11-16 17:26:20

标签: c linux shared-memory

如果已经分配了一些内存(例如使用malloc),那么可以将该内存与另一个进程共享,例如将页面标记为共享吗?

要明确的是,这与最初将内存分配为共享内存不同,例如使用shmget等。显然可以使用memcpy执行此操作,但有没有办法直接执行此操作?

1 个答案:

答案 0 :(得分:2)

mmap() creates a new mapping in the virtual address space of the calling process.
The starting address for the new mapping is specified in addr.
The length argument specifies the length of the mapping.

所以我想:

  • 在捐赠过程中打开一个文件进行写作。
  • mmap()您现有的malloc内存。
  • 在另一个进程中打开同一个文件。
  • 享受共享记忆。
相关问题