在 C++ 中实现共享内存管理器
我实现了一个简单的共享内存代码,该代码分散在两个进程中(1 个充当编写者,其他充当读者)。但我想管理这个 SHM 代码(就像内存管理器一样),它独立于任何读取器/写入器进程工作。通过简单地向外部提供一些钩子/指针,任何人都可以建议我一种方法。或与此相关的信息的任何相关代码或链接?还有一个我可以使用 Zygote 进程来实现这一点吗?请提出建议?
I have implemented a simple shared memeory code which is scattered in the two processes(1 acts writer and other acts as reader). But I want manage this SHM code(just like a memory manager),which works independent of any reader/writer processes. By simply giving some hooks/pointers to out side, Can any one suggests me a way for this. or any related code or links regarding related information to this ? One more this Can I use Zygote process to make it happen please suggest ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应用程序无法在现代操作系统上使用普通指针“共享”其内存。这需要操作系统的帮助,并且高度依赖于所讨论的操作系统。例如,在 Linux 上,最好的选择是使用 SysV 共享内存。
确保您了解多进程共享内存的开销,并问问自己是否仅使用线程还不够。在大多数情况下,线程就足够了,否则您应该重新考虑您的模型以使用消息传递/无共享模型。
An application cannot "share" its memory using plain pointers on a modern operating system. This is something which requires the assistance of the OS, and is highly dependent on the OS in question. For instance, on Linux the best bet would be to use SysV Shared Memory.
Make sure you understand the overhead of multiple process shared memory and ask yourself if just using threads would not suffice. In most cases, threads will suffice, or if not you should re-think your model to use a message passing/shared nothing model.
看看 Boost.Iterprocess 可以做什么你。特别要看看托管内存段部分。
Have a look at what Boost.Iterprocess can do for you. Especially have a look at the Managed Memory Segments section.