MapViewOfFile Perform Memoryapi.h
Maps a view of a file mapping into the deal with house of a calling course of. To specify a advised base address for the view, use the MapViewOfFileEx operate. However, this apply will not be recommended. A handle to a file mapping object. The CreateFileMapping and OpenFileMapping functions return this handle. The type of access to a file mapping object, which determines the web page protection of the pages. This parameter can be one in all the next values, or a bitwise OR mixture of a number of values the place applicable. Utilizing bitwise OR, you possibly can combine the values above with these values. When a process writes to a duplicate-on-write web page, the system copies the original web page to a brand new page that is non-public to the method. The brand new web page is backed by the paging file. The safety of the brand new page changes from copy-on-write to read/write. When copy-on-write entry is specified, the system and course of commit cost taken is for your complete view as a result of the calling process can doubtlessly write to each web page in the view, making all pages non-public.
The contents of the brand new page are by no means written again to the original file and are misplaced when the view is unmapped. Windows Server 2003 and Home windows XP: This value is offered starting with Windows XP with SP2 and Home windows Server 2003 with SP1. For more information about entry to file mapping objects, see File Mapping Security and Access Rights. A excessive-order DWORD of the file offset the place the view begins. A low-order DWORD of the file offset where the view is to start. The combination of the excessive and low offsets should specify an offset inside the file mapping. They should additionally match the digital Memory Wave Routine allocation granularity of the system. That's, the offset should 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 have to be within the maximum size specified by CreateFileMapping. If this parameter is zero (zero), the mapping extends from the specified offset to the tip of the file mapping.
If the function succeeds, the return value is the beginning handle of the mapped view. If the function fails, the return value is NULL. To get extended error Memory Wave information, call GetLastError. Mapping a file makes the required portion of a file visible in the handle space of the calling course of. For information that are larger than the handle house, you can only map a small portion of the file data at one time. When the primary view is complete, you possibly can unmap it and map a brand new view. To obtain the size of a view, use the VirtualQuery function. A number of views of a file (or a file mapping object and its mapped file) are coherent in the event that they contain similar information at a specified time. This happens if the file views are derived from any file mapping object that's backed by the identical file. A process can duplicate a file mapping object handle into one other process by using the DuplicateHandle function, or one other process can open a file mapping object by identify by using the OpenFileMapping perform.
With one vital exception, file views derived from any file mapping object that is backed by the same file are coherent or an identical at a specific time. Coherency is assured for views within a process and for views which can be mapped by completely different processes. The exception is expounded to remote files. Though MapViewOfFile works with remote recordsdata, it does not keep them coherent. For instance, if two computers each map a file as writable, and both change the same page, each computer solely sees its own writes to the page. When the info gets up to date on the disk, it is not merged. A mapped view of a file just isn't assured to be coherent with a file that is being accessed by the ReadFile or WriteFile perform. Do not retailer pointers in the Memory Wave mapped file; retailer offsets from the base of the file mapping in order that the mapping can be utilized at any address. ERROR exceptions, use structured exception dealing with to guard any code that writes to or reads from a memory mapped view of a file other than the page file. For more data, see Reading and Writing From a File View. When modifying a file by means of a mapped view, the final modification timestamp is probably not updated routinely. If required, the caller ought to use SetFileTime to set the timestamp. Worth), the paging file must be massive sufficient to carry all the mapping. If it is not, MapViewOfFile fails. The initial contents of the pages in a file mapping object backed by the paging file are zero (zero). RESERVE). Mapping the file makes your complete mapped virtual deal with vary unavailable to different allocations in the process. After a page from the reserved range is committed, it can't be freed or decommitted by calling VirtualFree. Reserved and committed pages are released when the view is unmapped and the file mapping object is closed. For particulars, see the UnmapViewOfFile and CloseHandle functions.