码迷,mamicode.com
首页 > Windows程序 > 详细

windows 文件内存映射

时间:2014-07-26 00:25:46      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   文件   re   c   div   

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 文件内存映射

标签:style   blog   color   os   文件   re   c   div   

原文地址:http://www.cnblogs.com/JonnyLulu/p/3868444.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!