MapViewOfFile Function Memoryapi.h
Maps a view of a file mapping into the handle space of a calling process. To specify a suggested base handle for the view, use the MapViewOfFileEx operate. Nevertheless, Memory Wave Protocol this apply shouldn't be advisable. A handle to a file mapping object. The CreateFileMapping and OpenFileMapping features return this handle. The type of access to a file mapping object, which determines the page safety of the pages. This parameter could be one among the following values, or a bitwise OR combination of a number of values where appropriate. Using bitwise OR, you can mix the values above with these values. When a course of writes to a copy-on-write page, the system copies the original page to a brand new page that is private to the method. The brand new web page is backed by the paging file. The protection of the brand new page adjustments from copy-on-write to learn/write. When copy-on-write entry is specified, the system and process commit charge taken is for your entire view because the calling course of can probably write to each web page in the view, making all pages non-public.
The contents of the new web page are by no means written back to the unique file and are lost when the view is unmapped. Home windows Server 2003 and Home windows XP: This worth is on the market beginning with Windows XP with SP2 and Home windows Server 2003 with SP1. For more details about access to file mapping objects, see File Mapping Safety 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 begin. The mix of the high and low offsets must specify an offset throughout the file mapping. They should also match the virtual Memory Wave Protocol allocation granularity of the system. That is, the offset have to 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 inside the utmost measurement specified by CreateFileMapping. If this parameter is zero (zero), the mapping extends from the required offset to the top of the file mapping.
If the operate succeeds, the return worth is the starting tackle of the mapped view. If the operate fails, the return worth is NULL. To get extended error information, name GetLastError. Mapping a file makes the required portion of a file seen within the address house of the calling course of. For information that are larger than the address house, you'll be able to only map a small portion of the file knowledge at one time. When the primary view is complete, you 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 in the event that they comprise an identical information at a specified time. This occurs if the file views are derived from any file mapping object that's backed by the same file. A course of can duplicate a file mapping object handle into another course of by utilizing the DuplicateHandle function, or another course of can open a file mapping object by title by using the OpenFileMapping function.
With one important exception, file views derived from any file mapping object that is backed by the same file are coherent or an identical at a particular time. Coherency is assured for views inside a process and for views which can be mapped by totally different processes. The exception is expounded to remote recordsdata. Although MapViewOfFile works with distant recordsdata, it does not keep them coherent. For instance, if two computers both map a file as writable, and each change the identical web page, each laptop solely sees its personal writes to the page. When the data gets up to date on the disk, it's not merged. A mapped view of a file is just not assured to be coherent with a file that's being accessed by the ReadFile or WriteFile perform. Don't store pointers in the memory mapped file; store offsets from the base of the file mapping so that the mapping can be utilized at any tackle. ERROR exceptions, use structured exception dealing with to protect any code that writes to or reads from a memory mapped view of a file aside from the web page file. For extra information, see Studying and Writing From a File View. When modifying a file by means of a mapped view, the final modification timestamp is probably not up to date routinely. If required, the caller ought to use SetFileTime to set the timestamp. Worth), the paging file have to be large enough to carry the complete mapping. If it's 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 the entire mapped virtual deal with vary unavailable to other allocations in the method. After a 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 details, see the UnmapViewOfFile and CloseHandle functions.