Shared memory in Ubuntu c ++

1

I try to make a couple of programs that work with shared memory (Server and client) in Ubuntu, for Windows I have found that you can create shared memory in the following way and it works well.

int BUF_SIZE = sizeof(Message) * 2;

string sharedName = "Global\MyFileMappingObject";
string message = "";
HANDLE hMapFile;
hMapFile = CreateFileMapping(
             INVALID_HANDLE_VALUE,    // use paging file
             NULL,                    // default security
             PAGE_READWRITE,          // read/write access
             0,                       // maximum object size (high-order DWORD)
             BUF_SIZE,                // maximum object size (low-order DWORD)
             sharedName.c_str()       // name of mapping object
);

However for Ubuntu I have not found the correspondence of this function that does the same as in Windows.

    
asked by AntoTGa 04.12.2017 в 08:58
source

1 answer

1

To do this in Ubuntu you can always directly access the POSIX API calls: mmap, as suggested by Trauma.

However, since you are on several different platforms, I would suggest using the boost interprocess, so that your code is portable. It comes pretty well explained here:

link

    
answered by 12.01.2018 / 00:35
source