0

I have an application where I have 3 different processes that need to run concurrently, in 3 different languages, on Windows:

  • A "data gathering" process, which interfaces with a sensor array. The developers of the sensor array have been kind enough to provide us with their C# source code, which I can modify. This should be generating raw data and shoving it into shared memory
  • A "post-processing" process. This is C++ code that uses CUDA to get the processing done as fast as possible. This should be taking raw data, moving it to the GPU, then taking the results from the GPU and communicating it to--
  • A feedback controller written in Matlab, which takes the results of the post-processing and uses it to make decisions on how to control a mechanical system.

I've done coursework on parallel programming, but that coursework all worked in Linux, where I used the mmap.h for coordination between multiple processes. This makes sense to me--you ask the OS for a page in virtual memory to be mapped to shared physical memory addresses, and the OS gives you some shared memory.

Googling around, it seems like the preferred way to set up shared memory between processes in Windows (in fact, the only "easy" way to do it in Matlab) is to use memory-mapped files, but this seems completely bonkers to me. If I'm understanding correctly, a memory-mapped file grabs some disk space and maps it to the physical address space, which is then mapped into the virtual address space for any process that accesses the same memory-mapped file.

This seems about three times more complex than it needs to be just to get multiple processes to map pages in their virtual address space to the same physical memory. I don't feel like I should be doing anything remotely related to disk I/O for what I'm trying to accomplish, especially since performance is a big issue for me (ideally I should be able to process 1000 sets of data per second, though that's not a hard limit). Is this really the right way to coordinate my processes?

Frank
  • 544
  • 2
  • 14
  • The `CreateFileMapping` function can also create shared memory without a file. Pass `INVALID_HANDLE_VALUE` instead of a file handle, and you get file-less shared memory. The function name is misleading, for which I apologize. – Raymond Chen Apr 11 '18 at 20:46
  • Thank you very much for the response, Raymond! From the documentation, `CreateFileMapping` with `INVALID_HANDLE_VALUE` creates a mapped memory file that is "backed by the system paging file." Is the system paging file not still space on the disk? Or does backing with the pagefile mean that the disk never gets involved because the pagefile is not a location you can directly write to? – Frank Apr 11 '18 at 22:02
  • That phrase has created more confusion than it was worth. All memory is backed by the system paging file. That's the point of virtual memory. So basically that is saying "If you pass `INVALID_HANDLE_VALUE`, then you get regular memory." (Okay, not all memory is backed by the system paging file. Memory-mapped files are backed by the file they were memory-mapped from. But all regular memory is backed by the system paging file.) – Raymond Chen Apr 11 '18 at 23:54

0 Answers0