Hi all, I am trying to use this concept of memory map IO to write data to disk at fast speeds. My program is time sensitive so it has to write a certain amount of data in a certain amount of time. It has to write a frame of data which is about 128k in less than 60 milliseconds. This has to be done repeatedly for around 20 thousand frames. I did the code for memory mapped IO and it works great, super fast. It writes at about 25 ms. However, after writing about 3000+ frames, my computer would freeze for like 10 seconds, then go back to writing again. I am using windows NT. Below is my code snippet:
//***************************************
unsigned short * startLoc;
HANDLE hFile;
HANDLE hMemMap;
OFSTRUCT finfo;
hFile = (HANDLE) OpenFile(filename.c_str(), &finfo, OF_CREATE); //OF_READ, OF_READWRITE, OF_WRITE
//Map file handle
hMemMap = CreateFileMapping (hFile, NULL, PAGE_READWRITE,
0, size , NULL);
//Map View of memory
startLoc = (unsigned short *) MapViewOfFile (hMemMap, FILE_MAP_WRITE, 0, 0,0);
//Write to file
memcpy(startLoc, lData, size);
//Close view
UnmapViewOfFile(startLoc);
//Close the mapping (writes dirty pages to disk)
CloseHandle(hMemMap);
hMemMap = NULL;
//Close the file
_lclose((HFILE)hFile);
//**************************************
if any1 have any idea on how to fix the computer freezing or has a clue to what is actually happening please help. Thanks alot.
//***************************************
unsigned short * startLoc;
HANDLE hFile;
HANDLE hMemMap;
OFSTRUCT finfo;
hFile = (HANDLE) OpenFile(filename.c_str(), &finfo, OF_CREATE); //OF_READ, OF_READWRITE, OF_WRITE
//Map file handle
hMemMap = CreateFileMapping (hFile, NULL, PAGE_READWRITE,
0, size , NULL);
//Map View of memory
startLoc = (unsigned short *) MapViewOfFile (hMemMap, FILE_MAP_WRITE, 0, 0,0);
//Write to file
memcpy(startLoc, lData, size);
//Close view
UnmapViewOfFile(startLoc);
//Close the mapping (writes dirty pages to disk)
CloseHandle(hMemMap);
hMemMap = NULL;
//Close the file
_lclose((HFILE)hFile);
//**************************************
if any1 have any idea on how to fix the computer freezing or has a clue to what is actually happening please help. Thanks alot.