about Memory-Mapped Files do with the big file.
-
i have wirtten a demo, which i want to chip the big file into the small ones by Memory-Mapped Files. the main code: HANDLE hFile = CreateFile(filePathName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL); pvFile = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, dwCurPart); HANDLE hNewFile = CreateFile(fileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE hNewFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwCurPart, NULL); PVOID pvNewFile = MapViewOfFile(hNewFileMap, FILE_MAP_WRITE, 0, 0, 0); memcpy(pvNewFile, pvFile, dwCurPart); i can get the new files,but the file don't get any content.i think the "memcpy();" can let the content copy into the new files. thanks for your help.
-
i have wirtten a demo, which i want to chip the big file into the small ones by Memory-Mapped Files. the main code: HANDLE hFile = CreateFile(filePathName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE hFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL); pvFile = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, dwCurPart); HANDLE hNewFile = CreateFile(fileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); HANDLE hNewFileMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, dwCurPart, NULL); PVOID pvNewFile = MapViewOfFile(hNewFileMap, FILE_MAP_WRITE, 0, 0, 0); memcpy(pvNewFile, pvFile, dwCurPart); i can get the new files,but the file don't get any content.i think the "memcpy();" can let the content copy into the new files. thanks for your help.
You have set the
dwNumberOfBytesToMap
parameter for the destination file to 0. Memory mapped files cannot grow like a disk files. You have to create the destination file with blanks and set thedwNumberOfBytesToMap
to the desired number of bytes. To create a blank file useSetEndOfFile
after theCreateFile
call.«_Superman_»
I love work. It gives me something to do between weekends.modified on Tuesday, May 25, 2010 12:09 PM