windows 文件内存映射
2020-12-13 05:25
标签:style blog color os 文件 re c div windows 文件内存映射,搜素材,soscw.com windows 文件内存映射 标签:style blog color os 文件 re c div 原文地址:http://www.cnblogs.com/JonnyLulu/p/3868444.htmlstatic int MapLogFile(void)
{
hFile = CreateFile(".\\db.bin",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
NULL);
if (INVALID_HANDLE_VALUE == hFile) {
goto err;
}
hMap = CreateFileMapping(hFile,
NULL,
PAGE_READWRITE,
0, MAP_LENGTH,
NULL);
if(0 == hMap) {
goto err_map;
}
MemAddrBegin = (unsigned char *)MapViewOfFile(hMap,
FILE_MAP_ALL_ACCESS,
0, 0,
0);
if(0 == MemAddrBegin) {
goto err_view;
}
return 0;
err_view:
CloseHandle(hMap);
err_map:
CloseHandle(hFile);
err:
return -1;
}
static int UnMapLogFile(void)
{
UnmapViewOfFile(MemAddrBegin);
CloseHandle(hMap);
CloseHandle(hFile);
return 0;
}
上一篇:jquery ajax无刷新删除