Skip to main content
FlushViewOfFile function

Writes to the disk a byte range within a mapped view of a file.


BOOL WINAPI FlushViewOfFile(
  _In_ LPCVOID lpBaseAddress,
  _In_ SIZE_T  dwNumberOfBytesToFlush


lpBaseAddress [in]

A pointer to the base address of the byte range to be flushed to the disk representation of the mapped file.

dwNumberOfBytesToFlush [in]

The number of bytes to be flushed. If dwNumberOfBytesToFlush is zero, the file is flushed from the base address to the end of the mapping.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.


Flushing a range of a mapped view initiates writing of dirty pages within that range to the disk. Dirty pages are those whose contents have changed since the file view was mapped. The FlushViewOfFile function does not flush the file metadata, and it does not wait to return until the changes are flushed from the underlying hardware disk cache and physically written to disk. To flush all the dirty pages plus the metadata for the file and ensure that they are physically written to disk, call FlushViewOfFile and then call the FlushFileBuffers function.

When flushing a memory-mapped file over a network, FlushViewOfFile guarantees that the data has been written from the local computer, but not that the data resides on the remote computer. The server can cache the data on the remote side. Therefore, FlushViewOfFile can return before the data has been physically written to disk.

When modifying a file through a mapped view, the last modification timestamp may not be updated automatically. If required, the caller should use SetFileTime to set the timestamp.

In Windows Server 2012, this function is supported by the following technologies.


Server Message Block (SMB) 3.0 protocol


SMB 3.0 Transparent Failover (TFO)


SMB 3.0 with Scale-out File Shares (SO)


Cluster Shared Volume File System (CsvFS)


Resilient File System (ReFS)



When CsvFs is paused this call might fail with an error indicating that there is a lock conflict.


For an example, see Reading and Writing From a File View.


Minimum supported client

Windows XP [desktop apps | UWP apps]

Minimum supported server

Windows Server 2003 [desktop apps | UWP apps]

Minimum supported phone

Windows Phone 8


WinBase.h (include Windows.h)





See also

Creating a File View
File Mapping Functions