简体   繁体   English

没有内存映射文件的共享内存

[英]Shared memory without memory-mapped files

Is it possible to share memory between two MFC C++ applications without using Memory mapped files ? 是否可以在两个MFC C ++应用程序之间共享内存而不使用内存映射文件 Currently we are using this method to share structs, and it is too slow for our requirements. 当前,我们正在使用此方法来共享结构,对于我们的要求而言,它太慢了。 Is there a better way? 有没有更好的办法?

Are you sure it is the memory mapped files that are slow? 您确定是内存映射文件很慢吗? The OS maps the same piece of RAM into both process spaces (when it's paged in.) Other culprits to performance issues could be mutexes and other synchronization primitives/volatile reads and cache invalidation to propagate concurrent changes to memory between processes. 操作系统将同一块RAM映射到两个进程空间中(在被分页时)。导致性能问题的其他原因可能是互斥体和其他同步原语/易失性读取以及缓存无效,以将并发的更改传播到进程之间的内存中。

You might try making changes locally to a non-shared region, and then bulk copying that, rather than repeatedly writing to the shared memory. 您可以尝试在本地对非共享区域进行更改,然后将其批量复制,而不是重复写入共享内存。

Other alternatives are message passing, RPC or DCOM, but I doubt these will be more performant, especially if the amount of data being transferred/referenced is large. 其他替代方法是消息传递,RPC或DCOM,但我怀疑它们是否会更具性能,尤其是在要传输/引用的数据量很大的情况下。

I would have thought that once you'd established the memory mapping (with the MapViewOfFile), that would be pretty fast. 我以为,一旦您建立了内存映射(使用MapViewOfFile),那将会非常快。

Is your performance problem with actually setting up the mapped memory, rather than using it once it's set up? 实际设置映射的内存而不是在设置之后立即使用它,是否会带来性能问题?

If you do genuinely have a verified problem with the memory mapped files, this is another technique: http://msdn.microsoft.com/en-us/library/h90dkhs0%28VS.80%29.aspx (DLL shared memory segments), but I doubt it's really going to help you. 如果确实确实存在内存映射文件的已验证问题,则这是另一种技术: http : //msdn.microsoft.com/zh-cn/library/h90dkhs0%28VS.80%29.aspx (DLL共享内存段) ,但我怀疑这真的会对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM