Create a shared memory segment

Flaviu_ 1,031 Reputation points
2020-10-09T07:08:20.59+00:00

Hello. How can I create a shared memory segment, in Windows ? I ask this because I have found several examples for Linux, but I need it in Windows.

There, I need to write and read char* on a given position ... but I don't know how to accomplish that. Can you help me ?

Windows development Windows API - Win32
Developer technologies C++
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 90,521 Reputation points
    2020-10-09T07:26:12.77+00:00

    You can see MSDN docs, like Sharing Files and Memory


  2. RLWA32 49,461 Reputation points
    2020-10-09T10:57:25.353+00:00

    There, I need to write and read char* on a given position

    Shared memory using CreateFileMapping and MapViewOfFile is made accessible to a process at a virtual address that is valid in that process. A pointer (e.g., char*) that is stored in shared memory will not be valid when that shared memory is mapped into a different process. And shared memory can be mapped to different virtual addresses in the various process that share it.

    Storing data in shared memory doesn't present a problem. However, storing pointers is another thing. A mechanism for using pointers in shared memory is to use Based Pointers which work with offsets.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.