我可以将一个对象的指针传递到共享内存吗?

问题描述:

我有一个非常复杂的类(它内部具有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.