The MapViewOfFile function maps a view of a file into the address space of the calling process.
LPVOID MapViewOfFile(
HANDLE hFileMappingObject, | // file-mapping object to map into address space |
DWORD dwDesiredAccess, | // access mode |
DWORD dwFileOffsetHigh, | // high-order 32 bits of file offset |
DWORD dwFileOffsetLow, | // low-order 32 bits of file offset |
DWORD dwNumberOfBytesToMap | // number of bytes to map |
); |
Value | Meaning |
FILE_MAP_WRITE | Read-write access. The hFileMappingObject parameter must have been created with PAGE_READWRITE protection. A read-write view of the file is mapped. |
FILE_MAP_READ | Read-only access. The hFileMappingObject parameter must have been created with PAGE_READWRITE or PAGE_READONLY protection. A read-only view of the file is mapped. |
FILE_MAP_ALL_ACCESS | Same as FILE_MAP_WRITE. |
FILE_MAP_COPY | Copy on write access. If
you create the map with PAGE_WRITECOPY and the view with FILE_MAP_COPY, you
will receive a view to file. If you write to it, the pages are automatically
swappable and the modifications you make will not go to the original data
file.
Windows 95: You must pass PAGE_WRITECOPY to CreateFileMapping; otherwise, an error will be returned. If you share the mapping between multiple processes using DuplicateHandle or OpenFileMapping and one process writes to a view, the modification is propagated to the other process. The original file does not change. Windows NT: There is no restriction as to how the hFileMappingObject parameter must be created. Copy on write is valid for any type of view. If you share the mapping between multiple processes using DuplicateHandle or OpenFileMapping and one process writes to a view, the modification is not propagated to the other process. The original file does not change. |
If the function succeeds, the return value is the starting address of the mapped view.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
Mapping a file makes the specified portion of the file visible in the address space of the calling process.
Once obtained, the handle to the memory-mapped file object is used to map views of the file to your process's address space. Views can be mapped and unmapped at will while the MMF object exists. When a view of the file is mapped, system resources are finally allocated. A contiguous range of addresses, large enough to span the size of the file view, are now committed in your process's address space. Yet, even though the addresses have been committed for the file view, physical pages of memory are still only committed on a demand basis when using the memory. So, the only way to allocate a page of physical memory for a committed page of addresses in your memory-mapped file view is to generate a page fault for that page. This is done automatically the first time you read or write to any address in the page of memory.
Multiple views of a file (or a file-mapping object and its mapped file) are said to be coherent if they contain identical data at a specified time. This occurs if the file views are derived from the same file-mapping object. A process can duplicate a file-mapping object handle into another process by using the DuplicateHandle function, or another process can open a file-mapping object by name by using the OpenFileMapping function.
A mapped view of a file is not guaranteed to be coherent with a file being accessed by the ReadFile or WriteFile function.
Windows 95: MapViewOfFile may require the swapfile to grow. If the swapfile cannot grow, the function fails.
Windows NT: If the file-mapping object is backed by the paging file (handle = 0xFFFFFFFF), the paging file must be large enough to hold the entire mapping. If it is not, MapViewOfFile fails.
CreateFileMapping, DuplicateHandle, GetSystemInfo, MapViewOfFileEx, OpenFileMapping, UnmapViewOfFile, SYSTEM_INFO
file: /Techref/os/win/api/win32/func/src/f56_17.htm, 8KB, , updated: 2001/10/22 13:16, local time: 2024/10/10 12:26,
98.84.18.52:LOG IN ©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://massmind.org/techref/os/win/api/win32/func/src/f56_17.htm"> MapViewOfFile</A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to massmind.org! |
.