// JP opened flex table

Click to See Complete Forum and Search --> : Writing File using CreateFileMapping - Please help


Ali Imran
July 4th, 2008, 04:07 AM
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


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

DreamShore
July 4th, 2008, 04:58 AM
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.

//JP added flex table