Click to See Complete Forum and Search --> : Retaining file mapping object after process exit


ajay.lele
August 14th, 2009, 08:00 PM
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/library/aa366556(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

Codeplug
August 14th, 2009, 08:51 PM
>> 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

ajay.lele
August 17th, 2009, 03:22 PM
Okay. Thanks. Will implement it using disk files.

Arjay
August 18th, 2009, 09:36 AM
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.