I'm kind of new to shared memory and i was searching for a working example, i managed to find only over MSDN
On the first process i've declared my shared memory as following:
hFileMapping = ::CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, dwDataSize, strSharedMemoryName.c_str());
pBuffer = ::MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0, dwDataSize);
::CopyMemory(pBuffer, pData, dwDataSize);
and on the second process:
HANDLE hFileMap = ::OpenFileMapping(FILE_MAP_READ, FALSE, strContentsSizeFileMap.c_str());
LPVOID pData = ::MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0);
I know that once I'm done working on the mapView, i need to release it using 'UnmapViewOfFile()
'. My question is where exactly?
- Parent Process?
- Child Process
- Both?
If it's on both, does the OS keep some reference count on the address before it's fully released?
From MSDN:
It also decrements the share count of the corresponding physical page
which got me a little bit confused regarding what im actually supposed to do.