开发者

How to implement a hello world shared memory in c/c++ in windows?

开发者 https://www.devze.com 2023-01-13 08:42 出处:网络
Is shared memory stable at the first place? I prefer this way to inter-开发者_如何学运维process/application communication because that way I don\'t need the overhead of parsing data.

Is shared memory stable at the first place?

I prefer this way to inter-开发者_如何学运维process/application communication because that way I don't need the overhead of parsing data.

Is there a good hello world demo on this in c/c++?


You should check out Boost.Interprocess. It provides the functionality you need and the documentation contains instructions on how to use it.


There are some issues you need to think of when using shared memory:

  1. You need to lock accesses to the shared memory so no process attempts to read from it while another process is writing to it to prevent reading a partially updated (inconstant).
  2. You need some way to handle corruption of the shared memory. What happens when a program that is writing to the shared memory crashes and leaves the shared memory in corrupt?


Is shared memory stable at the first place?

Yes.

I prefer this way to inter-process/application communication because that way I don't need the overhead of parsing data.

You may be wrong.

Is there a good hello world demo on this in c/c++?

I that you want something like Managing Memory-Mapped Files.


It's as stable as your code.

Note that there's no parsing required with any IPC method that supports binary messages,, such as UDP datagrams, message-mode pipes, or mailslots.


If you're looking for a simple example, Using Shared Memory in a Dynamic-Link Library from MSDN is probably a good starting point.

0

精彩评论

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

关注公众号