Windows 中的 msync 等价物 [英] msync equivalent in Windows

查看:103
本文介绍了Windows 中的 msync 等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

windows 中 msync [unix sys call] 的等价物是什么?我正在 C、C++ 空间中寻找 MSDN api.有关 msync 的更多信息,请访问 http://opengroup.org/onlinepubs/007908799/xsh/msync.html

what is the equivalent of msync [unix sys call] in windows? I am looking for MSDN api in c,C++ space. More info on msync can be found at http://opengroup.org/onlinepubs/007908799/xsh/msync.html

推荐答案

FlushViewOfFile

FlushViewOfFile

查看 Python 2.6 mmapmodule.c 中的 FlushViewOfFile 和 msync 使用示例:

Checkout the Python 2.6 mmapmodule.c for an example of FlushViewOfFile and msync in use:

/*
 /  Author: Sam Rushing <rushing@nightmare.com>
 /  Hacked for Unix by AMK
 /  $Id: mmapmodule.c 65859 2008-08-19 17:47:13Z thomas.heller $

 / Modified to support mmap with offset - to map a 'window' of a file
 /   Author:  Yotam Medini  yotamm@mellanox.co.il
 /
 / mmapmodule.cpp -- map a view of a file into memory
 /
 / todo: need permission flags, perhaps a 'chsize' analog
 /   not all functions check range yet!!!
 /
 /
 / This version of mmapmodule.c has been changed significantly
 / from the original mmapfile.c on which it was based.
 / The original version of mmapfile is maintained by Sam at
 / ftp://squirl.nightmare.com/pub/python/python-ext.
*/

static PyObject *
mmap_flush_method(mmap_object *self, PyObject *args)
{
    Py_ssize_t offset = 0;
    Py_ssize_t size = self->size;
    CHECK_VALID(NULL);
    if (!PyArg_ParseTuple(args, "|nn:flush", &offset, &size))
        return NULL;
    if ((size_t)(offset + size) > self->size) {
        PyErr_SetString(PyExc_ValueError, "flush values out of range");
        return NULL;
    }
#ifdef MS_WINDOWS
    return PyInt_FromLong((long) FlushViewOfFile(self->data+offset, size));
#elif defined(UNIX)
    /* XXX semantics of return value? */
    /* XXX flags for msync? */
    if (-1 == msync(self->data + offset, size, MS_SYNC)) {
        PyErr_SetFromErrno(mmap_module_error);
        return NULL;
    }
    return PyInt_FromLong(0);
#else
    PyErr_SetString(PyExc_ValueError, "flush not supported on this system");
    return NULL;
#endif
}

更新:我认为您不会在 win32 映射文件 API 中找到完整的奇偶校验.FlushViewOfFile API 没有同步风格(可能是因为缓存管理器的可能影响).如果需要精确控制何时将数据写入磁盘,也许您可​​以在创建映射文件的句柄时将 FILE_FLAG_NO_BUFFERINGFILE_FLAG_WRITE_THROUGH 标志与 CreateFile API 一起使用?

UPDATE: I don't think you are going to find complete parity in the win32 mapped file APIs. The FlushViewOfFile API doesn't have a synchronous flavor (probably because of the possible impact of the cache manager). If precise control over when data is written to disk is required perhaps you can use the FILE_FLAG_NO_BUFFERING and FILE_FLAG_WRITE_THROUGH flags with the CreateFile API when you create the handle to your mapped file?

这篇关于Windows 中的 msync 等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆