MapViewOfFile Operate (Memoryapi.h)
Bridget Fowlkes editou esta página 2 meses atrás


Maps a view of a file mapping into the address space of a calling course of. To specify a advised base handle for the view, use the MapViewOfFileEx function. However, this observe will not be beneficial. A handle to a file mapping object. The CreateFileMapping and OpenFileMapping functions return this handle. The type of entry to a file mapping object, which determines the page protection of the pages. This parameter can be one of the next values, or a bitwise OR combination of multiple values where applicable. Using bitwise OR, you possibly can combine the values above with these values. When a process writes to a duplicate-on-write page, the system copies the original page to a new web page that's private to the method. The brand new web page is backed by the paging file. The safety of the new web page modifications from copy-on-write to read/write. When copy-on-write access is specified, the system and process commit charge taken is for your entire view because the calling process can potentially write to every page in the view, making all pages personal.


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. Windows Server 2003 and Home windows XP: This value is accessible beginning with Windows XP with SP2 and Home windows Server 2003 with SP1. For extra details 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 begin. The mixture of the excessive and low offsets should specify an offset inside the file mapping. They must also match the digital Memory Wave App allocation granularity of the system. That is, the offset should be a multiple of the VirtualAlloc allocation granularity. The variety 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 0 (zero), the mapping extends from the required offset to the tip of the file mapping.


If the operate succeeds, the return worth is the beginning address 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 specified portion of a file visible within the address space of the calling process. For information which are larger than the address house, you can only map a small portion of the file knowledge at one time. When the primary view is full, you may unmap it and map a brand new view. To obtain the scale of a view, use the VirtualQuery operate. A number of views of a file (or a file mapping object and its mapped file) are coherent in the event that they include identical 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 utilizing the DuplicateHandle function, or one other course of can open a file mapping object by name by using the OpenFileMapping operate.


With one necessary exception, file views derived from any file mapping object that is backed by the identical file are coherent or similar at a selected time. Coherency is guaranteed for views within a process and for views which might be mapped by completely different processes. The exception is said to remote information. Although MapViewOfFile works with distant information, it does not keep them coherent. For instance, Memory Wave App if two computer systems each map a file as writable, and both change the identical page, every computer only sees its personal writes to the page. When the data gets updated on the disk, it isn't 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