MapViewOfFile Perform (Memoryapi.h)
Maps a view of a file mapping into the address area of a calling course of. To specify a prompt base handle for the view, use the MapViewOfFileEx operate. Nevertheless, this practice isn't advisable. A handle to a file mapping object. The CreateFileMapping and OpenFileMapping capabilities return this handle. The type of entry to a file mapping object, which determines the web page safety of the pages. This parameter may be one in all the following values, or Memory Wave a bitwise OR mixture of multiple values the place appropriate. Utilizing bitwise OR, you may mix the values above with these values. When a process writes to a copy-on-write page, the system copies the original page to a new page that's non-public to the method. The brand new page is backed by the paging file. The protection of the brand new web page adjustments from copy-on-write to learn/write. When copy-on-write entry is specified, the system and course of commit charge taken is for the complete view because the calling process can probably write to every page within the view, making all pages private.
The contents of the brand new web page are never written again to the original file and are lost when the view is unmapped. Home windows Server 2003 and Windows XP: This worth is on the market starting with Home windows XP with SP2 and Home windows Server 2003 with SP1. For more details about entry to file mapping objects, see File Mapping Safety and Access 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 start. The mixture of the high and low offsets should specify an offset inside the file mapping. They should also match the digital memory allocation granularity of the system. That is, the offset must be a a number of of the VirtualAlloc allocation granularity. The variety of bytes of a file mapping to map to the view. All bytes must be within the utmost size specified by CreateFileMapping. If this parameter is zero (zero), the mapping extends from the specified offset to the top of the file mapping.
If the operate succeeds, the return value is the starting address of the mapped view. If the operate fails, the return worth is NULL. To get extended error data, call GetLastError. Mapping a file makes the desired portion of a file visible within the handle area of the calling process. For files which might be larger than the handle area, you'll be able to only map a small portion of the file data at one time. When the first view is full, you possibly can unmap it and map a brand new view. To acquire the scale of a view, use the VirtualQuery function. Multiple views of a file (or a file mapping object and its mapped file) are coherent in the event that they comprise similar knowledge 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 another process through the use of the DuplicateHandle function, or another process can open a file mapping object by title through the use of the OpenFileMapping operate.
With one necessary exception, file views derived from any file mapping object that's backed by the identical file are coherent or identical at a selected time. Coherency is assured for views within a course of and for views which might be mapped by totally different processes. The exception is said to remote information. Though MapViewOfFile works with remote information, it doesn't keep them coherent. For instance, if two computers each map a file as writable, and both change the same web page, each laptop solely sees its personal writes to the web page. When the information gets updated on the disk, it's not merged. A mapped view of a file will not be assured to be coherent with a file that's being accessed by the ReadFile or WriteFile function. Don't retailer pointers within the memory mapped file; store offsets from the bottom of the file mapping so that the mapping can be utilized at any tackle. ERROR exceptions, use structured exception dealing with to guard any code that writes to or Memory Wave reads from a Memory Wave Method mapped view of a file apart from the web page file. For more data, see Studying and Writing From a File View. When modifying a file via a mapped view, the final modification timestamp may not be up to date robotically. If required, the caller ought to use SetFileTime to set the timestamp. Worth), the paging file have to be massive sufficient to hold the whole 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 handle vary unavailable to different allocations in the method. After a web page from the reserved vary is dedicated, it can't be freed or decommitted by calling VirtualFree. Reserved and committed pages are launched when the view is unmapped and the file mapping object is closed. For particulars, see the UnmapViewOfFile and CloseHandle capabilities.