Board index » cppbuilder » when to call MapViewOfFile()
Mike Collins
![]() CBuilder Developer |
when to call MapViewOfFile()2008-06-30 06:50:20 AM cppbuilder100 Hay guys, just a really quick question. Post the other week about using Memory Mapped Files and Remy gave me a really good reply. Just to summarise, I have a service that creates a MMF. It protects access to it using a mutex. Client applications wait for the mutex to be release and then can read the data from the MMF. For the client, remy suggested this order of operations: --- application --- hMapping = OpenFileMapping(FILE_MAP_READ, FALSE, "MyFileMapping"); hMutex = OpenMutex(SYNCHRONIZE, FALSE, "MyFileMappingMutex"); ... // for each read operation... if( WaitForSingleObject(hMutex, 1000) == WAIT_OBJECT_0 ) { // Perform read operation on the MMF... ReleaseMutex(hMutex); } ... CloseHandle(hMutex); CloseHandle(hMapping); My question is, do you have to call MapViewOfFile() each time you read the MMF or can it be called once, initially. For example, should it be called from within the WaitForSingleObject() call? Seems to work either way, just want to know what is the best practice. Many thanks in advance, Mike |