MapViewOfFile Perform Memoryapi.h

From gpu
Revision as of 15:42, 13 September 2025 by ChongNeubauer67 (talk | contribs) (Created page with "<br>Maps a view of a file mapping into the address area of a calling process. To specify a suggested base address for the view, use the MapViewOfFileEx perform. However, this practice is not really useful. A handle to a file mapping object. The CreateFileMapping and OpenFileMapping capabilities return this handle. The type of access to a file mapping object, which determines the web page protection of the pages. This parameter may be certainly one of the following values...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Maps a view of a file mapping into the address area of a calling process. To specify a suggested base address for the view, use the MapViewOfFileEx perform. However, this practice is not really useful. A handle to a file mapping object. The CreateFileMapping and OpenFileMapping capabilities return this handle. The type of access to a file mapping object, which determines the web page protection of the pages. This parameter may be certainly one of the following values, or a bitwise OR mixture of a number of values where applicable. Using bitwise OR, you'll be able to mix the values above with these values. When a course of writes to a copy-on-write page, the system copies the original web page to a brand new page that's non-public to the method. The new page is backed by the paging file. The safety of the new page modifications from copy-on-write to learn/write. When copy-on-write entry is specified, the system and course of commit cost taken is for your entire view as a result of the calling course of can doubtlessly write to every page within the view, making all pages non-public.



The contents of the brand new web page are by no means written back to the unique file and are misplaced when the view is unmapped. Home windows Server 2003 and Windows XP: This worth is obtainable starting 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 high-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 mix of the high and low offsets must specify an offset within the file mapping. They must also match the virtual memory allocation granularity of the system. That's, the offset have to be a multiple of the VirtualAlloc allocation granularity. The variety of bytes of a file mapping to map to the view. All bytes have to be within the maximum measurement specified by CreateFileMapping. If this parameter is 0 (zero), the mapping extends from the required offset to the tip of the file mapping.



If the operate succeeds, the return value is the beginning address of the mapped view. If the function fails, the return value is NULL. To get extended error data, call GetLastError. Mapping a file makes the required portion of a file seen within the handle space of the calling process. For recordsdata which are larger than the deal with area, you possibly can only map a small portion of the file information at one time. When the primary view is full, you can unmap it and map a brand new view. To obtain the dimensions of a view, use the VirtualQuery perform. Multiple views of a file (or a file mapping object and its mapped file) are coherent if they comprise identical data 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 process can duplicate a file mapping object handle into one other course of by using the DuplicateHandle function, or another process can open a file mapping object by title by utilizing the OpenFileMapping function.



With one vital exception, file views derived from any file mapping object that's backed by the same file are coherent or an identical at a particular time. Coherency is guaranteed for views inside a process and for views which might be mapped by completely different processes. The exception is related to remote recordsdata. Though MapViewOfFile works with distant files, it does not keep them coherent. For instance, if two computer systems each map a file as writable, and each change the identical web page, each pc only sees its own writes to the web page. When the info will get up to date on the disk, it isn't merged. A mapped view of a file is not assured to be coherent with a file that is being accessed by the ReadFile or WriteFile function. Do not retailer pointers within the memory mapped file; retailer offsets from the bottom of the file mapping so that the mapping can be used at any deal with. ERROR exceptions, use structured exception dealing with to guard any code that writes to or reads from a Memory Wave Routine mapped view of a file other than the web page file. For extra information, see Reading and Writing From a File View. When modifying a file by way of a mapped view, the last modification timestamp might not be updated mechanically. If required, the caller ought to use SetFileTime to set the timestamp. Value), the paging file have to be massive sufficient to carry the entire mapping. If it is not, MapViewOfFile fails. The initial contents of the pages in a file mapping object backed by the paging file are 0 (zero). RESERVE). Mapping the file makes all the mapped virtual deal with vary unavailable to other allocations in the method. After a web page from the reserved range is committed, 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.