windows 文件内存映射

static 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;
}

windows 文件内存映射,布布扣,bubuko.com

windows 文件内存映射

上一篇:windows 获取已插入U盘


下一篇:Windchill 图文档DWG使用队列生成表示法