views:

102

answers:

2

hey. im trying to use 2 threads running simultaneously and both using FileMapping feature to map a file on memory via different handles. problem is the MapViewOfFile function sometimes allocates the mapping on both threads to the same offset of memory. i tried using mutex on those parts, but it seems after high usage i fail to write to the mapping location. tried using MapViewOfFileEx that gets a memory offset to use, but i dunno what offset should i provide it with. any help would be appreciated. thanks.

A: 

I ran a few tests and I don't get the same address for a mapped view unless both instances of the file mapping are marked read only, even if both views are mapped from the same file mapping object. The OS is going to map a view based on the process's address space, not based on which thread is opening the view. Can you show us the code that you are using to obtain your file handle, your file mapping handle, and your mapped view?

Aaron Klotz
A: 

Can you post code and a more detailed description of the "failure to write"? I am a big fan of memory mapped files (when they're appropriate) and would love to see more about this problem / help find an answer.

Sam Post