Search code examples
cwin32-process

CreateFileMapping is used to create shared memory in win32


CreateFileMapping is used to create shared memory in win32. Do need to synchronized shared memory read/write or it is done automatically ?


Solution

  • Your question was not clear about whether you use this for shared memory between threads or processes, so just to be sure: for threads you dont need a file-mapping, all memory in a single process is visible to all threads (and needs sync).

    To use it for shared memory between processes: yes you have to sync accesses to it explicitly because the system can not know whether consecutive writes to it are meant to be grouped as a single transaction or not. Tip to do this: To sync them you can not use criticalsections (they only work for threads within a process), you could use:

    http://msdn.microsoft.com/en-us/library/aa904937%28v=VS.85%29.aspx