-1

我会搞乱内存共享,而神蛋糕要我做标题所说的,因为在 20GB 以上,我将分配 256MB 块(永远没有其他大小)给某些用户并与其他进程映射(共享)它们. 64 位虚拟地址空间是巨大的(16EB)。只是我需要将用户管理器的代码和数据与用户的记忆分开。

完美将是这样的一些功能:

void *malloc(size_t n, void *from, void *to);
4

1 回答 1

1

Supposing you are on a system with POSIX support, you want to create or locate a shared memory segment with shmget, attach to it with shmat. When done, you detach with shmdt and remove the shared memory segment with shmctl. I leave it to you to read the documentation for these routines.

While shmat allows you to request a specific address at which to map the shared memory, there is generally no need to do so. You can pass zero for the address parameter, and shmat will pick an address. Setting a high address does nothing to separate the shared memory from other memory, except possibly to reduce or alter the errors that could be caused by buffer overruns writing to unintended places in memory.

于 2012-08-26T11:35:18.197 回答