Writing File using CreateFileMapping - Please help
Hello gurus
Can anyone please provide be a complete example of writing large files fast using File Maping functions ?
Following code cause application level crash
Code:
char *out = "newfile.txt";
HANDLE fh_infile = CreateFile(out, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(fh_infile==NULL) return false;
HANDLE h = CreateFileMapping(fh_infile, NULL, PAGE_READWRITE, 0, filesize, NULL);
char *dat = (char*)MapViewOfFile(h, FILE_MAP_WRITE, 0, 0, filesize);
char *tempdata = "Here is the temporary data";
CopyMemory(dat, tempdata, strlen(tempdata)+1);
UnmapViewOfFile(dat);
CloseHandle(fh_infile);
Waiting or the kind reply.
regards
Re: Writing File using CreateFileMapping - Please help
File mapping is not something to write file fast. It's more or less used to share pages between processes.
I rarely create file mapping on normal files... but I think the file should be opened with both read and write access since you want the page to be r&w.
Don't forget to close the file mapping.