How can I allocated shared memory to a static buffer like the following but using CreateFileMapping and MapViewOfFile.
#pragma data_seg(".ABC")
__declspec (dllexport) char buffer[10000] = {0};
#pragma data_seg()
#pragma comment(linker, "-section:.ABC,rws")
The goal is to create a static shared buffer that is shared between C++ and FORTRAN applications, like it's done when using data_seg. When creating a dynamic allocated buffer, FORTRAN gets tricky because you need to de-reference the pointer, which is also doable, but it's not what I want.
The equivalent Win32 API calls would look like this:
Both apps would have to call
CreateFileMapping()with the samelpNamevalue to gain access to the same mapping object in the system kernel. Whichever app callsCreateFileMapping()first will create the object, and the second app will get a handle to the existing object. Then,MapViewOfFile()maps memory access within the calling process to that object. In this way, both apps are using shared memory with each other. When one app writes data into the object, the other app will see it.