[Migrated content. Thread originally posted on 20 January 2012]
Hello All,
I am trying to explore whether we can used memory mapped files on windows to implement shared memory (using c ) that will be used from within cobol.
I have number of processes (running cobol code) that need to share a common memory area that could be implemented using memory mapped file.
I want to know if it is possible that this file can be accessed from within a cobol program (could a pointer be returned from a C code to cobol code so that we can set the address of a cobol structure to the memory mapped file)
I am using netexpress 5.1 and visual studio 2010 express.
-PTeng
It's certainly possible to use memory-mapped files from Micro Focus COBOL. It's also a terrific way to introduce intermittent bugs that are very difficult to diagnose and fix. Shared memory, particularly when used by code written in different languages, involves a host of difficult problems: internal data representation, synchronization, misuse of pointers, etc. Whatever problem you're looking to solve, shared memory mappings are probably not the best approach.
That said, the easiest way to use memory-mapped files from COBOL on Windows is to simply call the relevant Windows APIs (MapViewOfFile, etc). If the file is already mapped in the process, you can also just pass a pointer to the mapped data to COBOL; this doesn't work between processes, of course.