I am wondering if for this code snippet:
HANDLE fhandle = CreateFile("something.c", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE mapping = CreateFileMapping(fhandle, NULL, PAGE_READONLY, 0, 0, NULL);
LPVOID map_view = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
The following order of releasing objects is valid:
CloseHandle(mapping);
CloseHandle(fhandle);
UnmapViewOfFile(contents);
i.e. can I close file handle first and call UnmapViewOfFile
afterwards?
I know that execution order of CloseHandle(mapping)
and UnmapViewOfFile(contents)
is irrelevant, but what about closing the file handle?
I am asking because I would like to use only map_view
pointer for destructor. It seems to me that this works and that the file is held until UnmapViewOfFile
is called, but maybe this can cause some weird behavior?