2 out of 2 rated this helpful - Rate this topic

UnmapViewOfFile function

Applies to: desktop apps | Metro style apps

Unmaps a mapped view of a file from the calling process's address space.

Syntax

BOOL WINAPI UnmapViewOfFile(
  __in  LPCVOID lpBaseAddress
);

Parameters

lpBaseAddress [in]

A pointer to the base address of the mapped view of a file that is to be unmapped. This value must be identical to the value returned by a previous call to the MapViewOfFile or MapViewOfFileEx function.

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.

Remarks

Unmapping a mapped view of a file invalidates the range occupied by the view in the address space of the process and makes the range available for other allocations. It removes the working set entry for each unmapped virtual page that was part of the working set of the process and reduces the working set size of the process. It also decrements the share count of the corresponding physical page.

Modified pages in the unmapped view are not written to disk until their share count reaches zero, or in other words, until they are unmapped or trimmed from the working sets of all processes that share the pages. Even then, the modified pages are written "lazily" to disk; that is, modifications may be cached in memory and written to disk at a later time. To minimize the risk of data loss in the event of a power failure or a system crash, applications should explicitly flush modified pages using the FlushViewOfFile function.

Although an application may close the file handle used to create a file mapping object, the system holds the corresponding file open until the last view of the file is unmapped. Files for which the last view has not yet been unmapped are held open with no sharing restrictions.

Examples

For an example, see Creating a View Within a File.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Closing a File Mapping Object
File Mapping Functions
MapViewOfFile
MapViewOfFileEx
Memory Management Functions

 

 

Send comments about this topic to Microsoft

Build date: 2/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
C# syntax
[return: MarshalAs(UnmanagedType.Bool)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("Kernel32", CharSet=CharSet.Auto, SetLastError=true)]
internal static extern bool UnmapViewOfFile(IntPtr pvBaseAddress);
vb.net syntax
<ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), DllImport("Kernel32", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function UnmapViewOfFile(ByVal pvBaseAddress As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function