I am trying to read from a memory mapped file, but access to the file is taking a long time. I am mapping the whole file to my program, and initial access to fast, but then it begins to drastically slow down
The file is ~47gb and I have 16gb of RAM. I am running a 64-bit application on windows 7 using Visual Studios as my IDE. Below is snippet of my code
hFile = CreateFile( "Valid Path to file", // name of the write GENERIC_READ , // open for reading 0, // do not share NULL, // default security OPEN_EXISTING, // existing file only FILE_ATTRIBUTE_NORMAL, // normal file NULL); // no attr. template if (hFile == INVALID_HANDLE_VALUE) { cout << "Unable to open vals" << endl; exit(1); } hMapFile = CreateFileMapping( hFile, NULL, // default security PAGE_READONLY, // read/write access 0, // maximum object size (high-order DWORD) 0, // maximum object size (low-order DWORD) NULL); // name of mapping object if (hMapFile == NULL) { cout<< "Error code " << GetLastError() << endl; exit(1); } data = (float*) MapViewOfFile( hMapFile, FILE_MAP_READ, 0, 0, 0); if (data == NULL) { cout << "Error code " << GetLastError() << endl; CloseHandle(hFile); exit(1); } Is this just because the file is so large that continually swapping chunks of the file takes long, or is it some other parameter I need for faster access?
EDIT: I tried using read only instead of using read, write, execute as seen above, but the speed is still slow. I understand the concepts of memory mapping and switch swap space, but I thought I may have been doing something else wrong with was hindering the speed
PAGE_EXECUTE_READWRITEorGENERIC_EXECUTEfor a datafile.