开发者

How to implement a shared buffer?

开发者 https://www.devze.com 2023-03-25 22:19 出处:网络
I\'ve got one program which creates 3 worker programs. The preferable method of communication in my situation would be through a memory buffer which all four programs may access.

I've got one program which creates 3 worker programs. The preferable method of communication in my situation would be through a memory buffer which all four programs may access.

Is there a way to pass a pointer开发者_如何学编程, reference or any kind of handler to the child processes?

Update

The three child programs are transforming vertex data while the main program primarily deals with UI, system messages, errors, etc..

I'm hoping there is some way to leverage OpenCL such that the four programs can share a context. If this is not possible, it would be nice to have access to the array of vertices across all programs.

I suppose our target platform is Windows right now but we'd like to keep it as cross-platform as possible. If there is no way to implement this utilizing OpenCL we'll probably fall back to wrapping this piece of code for a handful of different platforms.


Your question is platform dependent, therefore :

  • for Windows : Named Shared Memory
  • for linux : mmap or POSIX shared memory access
  • general case : boost::interprocess


If you explain a bit what kind of data is shared and other constraints/goal of the system it would be easier to answer your question.

I wonder why you think a shared buffer would be good? Is that because you want to pass a pointer in the buffer to the data to be worked on? Then you need shared memory if you want to work across processes.

What about a client-server approach where you send data to clients on request?

More information about your problem helps giving a better answer.


You should use Named Shared Memory and inter-process synchronization.


This is somewhat wider than the original question on shared memory buffers, but depending on your design, volume of data and performance requirements you could look into in-memory databases such as Redis or distributed caches, especially if you find yourself in 'publish-subscribe' situation.

0

精彩评论

暂无评论...
验证码 换一张
取 消