|
关于文件映射在多线程中使用问题
又迟到了 你加我QQ 聊.. 这个太慢了..... |
|
关于文件映射在多线程中使用问题
这个是别人代码 我拿来修改的... DWORD WINAPI ThreadProc_Revert(LPVOID lpParameter) { if (pThreadinfo == NULL) { return 0; } THREAD_INFO *pThreadinfo = (THREAD_INFO*)lpParameter; // 创建目标文件 HANDLE hFile = CreateFile ( pThreadinfo->fileinfo.strFileName, GENERIC_READ | GENERIC_WRITE, \ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL ); // 创建文件内存映射内核对象 HANDLE hMapFile = CreateFileMapping ( hFile, NULL, PAGE_READWRITE, 0, 0, NULL ); if (hFile == NULL) { printf("Error Code:%d", GetLastError()); return 0; } TCHAR strChild[MAX_PATH] = {0}; DWORD64 dw64CurAddr = 0, dw64CurPart = 0; LPVOID lpMapAddr = 0; dw64CurAddr += pThreadinfo->dwoffset; dw64CurPart = pThreadinfo->fileinfo.dw64FileSize - pThreadinfo->dwoffset; if( dw64CurPart >pThreadinfo->fileinfo.dw64PartSize ) dw64CurPart = pThreadinfo->fileinfo.dw64PartSize; // 创建子文件的文件名 _stprintf_s(strChild,MAX_PATH,_T("%s.PART_%d"),pThreadinfo->fileinfo.strFileName, pThreadinfo->num); char aaa[MAX_PATH] ={0}; strncpy_s(aaa,MAX_PATH,CT2A(strChild),_TRUNCATE); if( dw64CurPart > SMALL_BLOCK_SIZE ) { // 打开分块子文件 HANDLE hCFile = CreateFile ( strChild, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, \ NULL, OPEN_EXISTING, 0, NULL ); // 创建子文件映射内核对象 HANDLE hCMapFile = CreateFileMapping ( hCFile, NULL, PAGE_READONLY, 0, 0, NULL ); DWORD64 dw64PartTemp = dw64CurPart + SMALL_BLOCK_SIZE; DWORD64 dw64AddrTemp = 0; while( dw64PartTemp > SMALL_BLOCK_SIZE ) { // 小块大小 DWORD dwPartTemp = ((dw64PartTemp - SMALL_BLOCK_SIZE) >= SMALL_BLOCK_SIZE ) ? \ SMALL_BLOCK_SIZE : ( dw64PartTemp % SMALL_BLOCK_SIZE ); // 映射子块的小块到内存 LPVOID lpCMapAddr = MapViewOfFile ( hCMapFile, FILE_MAP_READ, dw64AddrTemp / G4,\ dw64AddrTemp % G4, dwPartTemp ); if( NULL == lpCMapAddr ) { printf("Error Code:%d", GetLastError()); return FALSE; } dw64AddrTemp += dwPartTemp; // 映射要还原文件的小块到内存 lpMapAddr = MapViewOfFile ( hMapFile, FILE_MAP_WRITE, dw64CurAddr / G4, dw64CurAddr % G4, dwPartTemp ); if( NULL == lpMapAddr ) { printf("Error Code:%d", GetLastError()); return FALSE; } dw64CurAddr += dwPartTemp ; dw64PartTemp -= SMALL_BLOCK_SIZE; int dwT = dw64AddrTemp / (1024*1024) ; printf("%s 合并: %d(MB)..\r\n",aaa,dwT); // 将子块的小块数据复制到要还原的源文件小块中 memcpy ( lpMapAddr, lpCMapAddr, dwPartTemp ); // 更新数据到文件 FlushViewOfFile ( lpMapAddr, dwPartTemp ); UnmapViewOfFile ( lpCMapAddr ); UnmapViewOfFile ( lpMapAddr ); } CloseHandle ( hCFile ); CloseHandle ( hCMapFile ); } else { lpMapAddr = MapViewOfFile ( hMapFile, FILE_MAP_WRITE, 0, dw64CurAddr, dw64CurPart ); dw64CurAddr += dw64CurPart; // 打开子文件,并进行内存映射 HANDLE hCFile = CreateFile ( strChild, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, \ NULL, OPEN_EXISTING, 0, NULL ); HANDLE hCMapFile = CreateFileMapping ( hCFile, NULL, PAGE_READONLY, 0, 0, NULL ); LPVOID lpCMapAddr = MapViewOfFile ( hCMapFile, FILE_MAP_READ, 0, 0, 0 ); // 把子文件数据复制到还原源文件 memcpy ( lpMapAddr, lpCMapAddr, dw64CurPart ); //更新数据到文件 FlushViewOfFile ( lpMapAddr, dw64CurPart ); UnmapViewOfFile ( lpMapAddr ); UnmapViewOfFile ( lpCMapAddr ); CloseHandle ( hCFile ); CloseHandle ( hCMapFile ); } CloseHandle ( hMapFile ); CloseHandle ( hFile ); return 0; } |
|
关于文件映射在多线程中使用问题
难道就没有人遇到过这样的问题吗?? |
|
[求助]安装SPI 基础服务后的一个BUG
呵呵,测试程序!主要是测试这个问题的。 |
|
[求助]安装SPI 基础服务后的一个BUG
求解啊!!! |
|
[求助][求助]Help Me <CrackMe中的算法求助>
是的啊 ,谢谢啊!膜拜下。 |
|
[求助]关于_eprocess遍历进程问题
谢谢 已近解决! |
|
[求助]文件过滤驱动问题
是的,要获取读的内容是要等读完成后才能获得内容,所以设置了完成例程,等完成的时候出发事件,在派遣函数中从新获得IRP的操作权, 可是这样做蓝频啊~~ |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值