MapViewOfFile Perform (Memoryapi.h)
Alfredo McCleary 于 1 个月前 修改了此页面


Maps a view of a file mapping into the address area of a calling course of. To specify a recommended base address for the view, use the MapViewOfFileEx function. Nonetheless, this practice is just not really useful. A handle to a file mapping object. The CreateFileMapping and OpenFileMapping features return this handle. The type of entry to a file mapping object, which determines the web page safety of the pages. This parameter can be one among the next values, or a bitwise OR combination of multiple values where appropriate. Using bitwise OR, you possibly can combine the values above with these values. When a process writes to a replica-on-write page, the system copies the unique page to a brand new page that’s personal to the method. The new web page is backed by the paging file. The protection of the new page adjustments from copy-on-write to learn/write. When copy-on-write access is specified, the system and course of commit charge taken is for the complete view as a result of the calling process can potentially write to every web page within the view, making all pages personal.


The contents of the new web page are by no means written back to the original file and are misplaced when the view is unmapped. Windows Server 2003 and Windows XP: This value is on the market beginning with Windows XP with SP2 and Windows Server 2003 with SP1. For extra information about access to file mapping objects, see File Mapping Safety and Entry Rights. A excessive-order DWORD of the file offset where the view begins. A low-order DWORD of the file offset where the view is to begin. The combination of the excessive and low offsets must specify an offset throughout the file mapping. They should additionally match the virtual Memory Wave allocation granularity of the system. That’s, the offset must be a a number of of the VirtualAlloc allocation granularity. The number of bytes of a file mapping to map to the view. All bytes should be within the utmost dimension specified by CreateFileMapping. If this parameter is 0 (zero), the mapping extends from the desired offset to the tip of the file mapping.
ahajournals.org


If the perform succeeds, the return value is the beginning deal with of the mapped view. If the perform fails, the return worth is NULL. To get prolonged error information, name GetLastError. Mapping a file makes the required portion of a file seen within the deal with area of the calling process. For files which can be bigger than the handle house, you may only map a small portion of the file information at one time. When the first view is complete, you possibly can unmap it and map a brand new view. To obtain the size of a view, use the VirtualQuery perform. A number of views of a file (or a file mapping object and its mapped file) are coherent if they include equivalent data at a specified time. This occurs if the file views are derived from any file mapping object that is backed by the identical file. A course of can duplicate a file mapping object handle into another process through the use of the DuplicateHandle operate, or one other course of can open a file mapping object by name by using the OpenFileMapping perform.


With one necessary exception, file views derived from any file mapping object that is backed by the identical file are coherent or equivalent at a particular time. Coherency is guaranteed for views inside a course of and for views which can be mapped by completely different processes. The exception is said to remote information. Although MapViewOfFile works with distant files, it does not keep them coherent. For example, if two computers both map a file as writable, and each change the same page, every laptop solely sees its personal writes to the page. When the data gets updated on the disk, it is not merged. A mapped view of a file is just not assured to be coherent with a file that is being accessed by the ReadFile or WriteFile operate. Do not retailer pointers in the memory mapped file