I have a sort which creates some temp files if you're sorting too much to fit in RAM.
The temp files are managed with the following API sequence:
_hFile = CreateFile(filename.c_str(),GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_NEW,0,NULL);
_hMapping = CreateFileMapping(_hFile,NULL,PAGE_READWRITE|SEC_COMMIT,0,_filesize,NULL);
_currentView = (char *)MapViewOfFile(_hMapping,FILE_MAP_ALL_ACCESS,0,0,_desiredViewSize);
UnmapViewOfFile and MapViewOfFile are then called a number of times (always paired) when moving the view through the file or resizing it so that all views fit in memory and the process doesn't run into the 2GB limit.
Then when the file is done with:
UnmapViewOfFile(_currentView);
CloseHandle(_hMapping);
CloseHandle(_hFile);
DeleteFile and unlink are not working after the file is closed. How is the file being left open here?
The temp files are managed with the following API sequence:
_hFile = CreateFile(filename.c_str(),GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_NEW,0,NULL);
_hMapping = CreateFileMapping(_hFile,NULL,PAGE_READWRITE|SEC_COMMIT,0,_filesize,NULL);
_currentView = (char *)MapViewOfFile(_hMapping,FILE_MAP_ALL_ACCESS,0,0,_desiredViewSize);
UnmapViewOfFile and MapViewOfFile are then called a number of times (always paired) when moving the view through the file or resizing it so that all views fit in memory and the process doesn't run into the 2GB limit.
Then when the file is done with:
UnmapViewOfFile(_currentView);
CloseHandle(_hMapping);
CloseHandle(_hFile);
DeleteFile and unlink are not working after the file is closed. How is the file being left open here?