我可以将一个对象的指针传递到共享内存吗? [英] Can I pass an object to another process just passing its' pointer to a shared memory?

查看:169
本文介绍了我可以将一个对象的指针传递到共享内存吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常复杂的类(它内部具有unordered_map等),我想与我的两个进程共享该对象.我可以简单地将一个指向它的指针从一个进程传递到另一个进程吗?我认为不是,但是希望听到是!".

I have a very complicated class(it has unordered_map and so on on inside it) and I want to share an object of it withit two my processes. Can I simply pass just a pointer to it from one process to another? I think, no, but hope to hear "Yes!".

如果为否",我将很高兴看到任何链接在这种情况下如何应对. 对于所有进程,我只需要有该对象的一个​​实例,因为它非常大,并且所有进程都可以正常工作,仅供只读.

If "no", I'd be grateful to see any links how to cope in such cases. I need to have only one instance of this object for all processes because it's very large and all of the processes will work woth it for read only.

推荐答案

不,进程不(自然)共享内存.如果可以选择boost,那么您可以查看 Boost.Interprocess 用于轻松共享内存.

No, process do not (naturally) share memory. If boost is an option, so you can have a look on Boost.Interprocess for easy memory sharing.

这篇关于我可以将一个对象的指针传递到共享内存吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆