Thread: Sharing a Memory Space between two Processes

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    6

    Sharing a Memory Space between two Processes

    Dear All,
    I have a linux-based application, and a Windows C code in Visual Studio.
    The Linux based library is built under MinGW.
    I want to share a video file between these two, say processes (as I run my Windows C code in Visual Studio, and this library's dlls, and lib's which are used in Visual Studio program are created under MinGW)
    I simply want to open my video file in visual studio, then pass it to MinGW built library (using one of the functions in that library in Visual Studio code), and then this library will do some processing on the video file, and save it for me.

    Initially, I thought the solution of Shared Memory should work, as both Visual Studio ,and MinGW understand CreateFileMapping(), and OpenFileMapping()
    But now I see that whatever I write to named shared memory in visual studio, I cannot read in MinGW.
    I even tried to write a simple string like "Hello World" in Visual Studio, and read it from the Shared Memory in MinGW, but the string isn't there apparently.
    So, my question:
    Is it possible to share a memory space between Visual Studio ,and MinGW? (I mean, was it a fault with my programs or it is the way it is!! [I think my program should work, as the same shared memory works between two Visual Studio samples])
    And if not, what is your suggestion to my initial problem as described above (any other approach than shared memory?)

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need to use the File Mapping Functions - if you don't want to also create a file to back the mapping with, you can specify INVALID_HANDLE_VALUE as the first parameter to CreateFileMapping(), and it will use the system swap file as the backing store.

    Memory Management Functions (Windows)

    Note that although it says that there is a backing file, the data is held in memory if there is enough free memory in the machine. Only if the machine is short of memory is data stored on disk.

    [And it's probably better to have a local named file than to use the swap-file, particularly if the system is short of swap-space]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 10:48 PM
  2. Suggestions on this C style code
    By Joelito in forum C Programming
    Replies: 11
    Last Post: 06-07-2007, 03:22 AM
  3. Reading and editing another processes memory
    By Doodle77 in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 03:53 AM
  4. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM
  5. Managing shared memory lookups
    By clancyPC in forum Linux Programming
    Replies: 0
    Last Post: 10-08-2003, 04:44 AM