CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    4

    Retaining file mapping object after process exit

    Hi,

    I am writing a small library using Win32 APIs and it needs to provide Linux like shared memory support. Trying to use file mapping objects backed by system paging file
    http://msdn.microsoft.com/en-us/libr...56(VS.85).aspx

    Problem is even if the process does not explicitly close the handler to mapped object, it is destroyed when the process exists (guess Windows decrements the handle refcount when process exists and since it reaches 0, mapped object is destroyed). So another process which might start after the 1st process exited would not be able to see the mapped object. This behaviour is different from Linux implementation wherein the shared memory is not destroyed until shm_unlink is done explicitly. Is there a way to not have the file mapping object to be destroyed when the process exists (and no other handle to it is open from another process)

    Thanks in advance

    Regards

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    Re: Retaining file mapping object after process exit

    >> Trying to use file mapping objects backed by system paging file
    It needs to be "backed" by a real file if you want it to persist while no processes have a handle open to it.

    gg

  3. #3
    Join Date
    Aug 2009
    Posts
    4

    Re: Retaining file mapping object after process exit

    Okay. Thanks. Will implement it using disk files.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Retaining file mapping object after process exit

    I like the fact that Windows does it both ways. In the cases where you don't need the persistent behavior, the page file backing is sure handy because you don't need to worry about cleaning up the file when you are done.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured