是否可以通过名称打开共享内存段?
char* openSharedMemory(string name);
上面的功能可以实现吗?给定一个名称,打开具有该名称的共享内存段并将句柄返回到共享内存。如果给定名称的共享内存不存在,则创建一个并返回句柄。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
char* openSharedMemory(string name);
上面的功能可以实现吗?给定一个名称,打开具有该名称的共享内存段并将句柄返回到共享内存。如果给定名称的共享内存不存在,则创建一个并返回句柄。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
是的,看看
shm_overview( 7)
如果您使用的是最新的 Unix,shm_open(3)
。Yes, take a look at
shm_overview(7)
if you are on any recent Unix,shm_open(3)
in particular.好吧, boost::interprocess< /a> 支持这个..
Well, boost::interprocess supports this..
可移植的是,您可以使用 Boost.Interprocess。
在 Posix 上,您可以这样做:
尽管您应该将其包装在一个类中,但要保留文件描述符,以便它可以在销毁时取消映射并关闭共享内存对象。
Portably, you can use Boost.Interprocess.
On Posix, you could do something like this:
Although you should wrap it in a class, to keep hold of the file descriptor so it can unmap and close the shared memory object on destruction.
如果是 Windows,请考虑使用内存映射文件。
If Windows, look into using a memory-mapped file.
在 Windows 上,查看 MemoryMappedFiles 和 CreateFileMapping 以及名称
On windows look at MemoryMappedFiles and CreateFileMapping with a name