MapViewOfFile Operate Memoryapi.h

From GoldenWiki - Community Building
Jump to navigation Jump to search


Maps a view of a file mapping into the tackle house of a calling course of. To specify a instructed base tackle for the view, use the MapViewOfFileEx function. Nevertheless, this observe is just not really helpful. A handle to a file mapping object. The CreateFileMapping and OpenFileMapping features return this handle. The type of entry to a file mapping object, which determines the page safety of the pages. This parameter might be one in every of the following values, or a bitwise OR combination of multiple values where applicable. Utilizing bitwise OR, you'll be able to mix the values above with these values. When a process writes to a copy-on-write page, the system copies the original web page to a new page that is private to the process. The new web page is backed by the paging file. The protection of the brand new web page modifications from copy-on-write to learn/write. When copy-on-write entry is specified, the system and process commit cost taken is for your complete view as a result of the calling process can probably write to every web page within the view, making all pages private.



The contents of the brand new page are by no means written back to the unique file and are lost when the view is unmapped. Home windows Server 2003 and Windows XP: This value is offered beginning with Windows XP with SP2 and Windows Server 2003 with SP1. For extra information about access to file mapping objects, see File Mapping Security and Entry Rights. A high-order DWORD of the file offset where the view begins. A low-order DWORD of the file offset the place the view is to begin. The combination of the high and low offsets should specify an offset within the file mapping. They must additionally match the virtual Memory Wave memory booster 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 should be within the utmost measurement specified by CreateFileMapping. If this parameter is zero (zero), the mapping extends from the desired offset to the end of the file mapping.



If the function succeeds, the return value is the starting address of the mapped view. If the function fails, the return worth is NULL. To get extended error information, call GetLastError. Mapping a file makes the specified portion of a file seen in the deal with space of the calling process. For files that are larger than the handle space, you'll be able to only map a small portion of the file information at one time. When the first view is complete, you can unmap it and map a brand new view. To acquire the scale of a view, use the VirtualQuery operate. Multiple views of a file (or a file mapping object and its mapped file) are coherent if they contain equivalent 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 course of can duplicate a file mapping object handle into another course of by utilizing the DuplicateHandle operate, or one other process can open a file mapping object by identify by utilizing the OpenFileMapping operate.



With one essential exception, file views derived from any file mapping object that is backed by the same file are coherent or equivalent at a specific time. Coherency is assured for views within a process and for views which might be mapped by totally different processes. The exception is expounded to remote recordsdata. Although MapViewOfFile works with distant files, it doesn't keep them coherent. For instance, if two computers both map a file as writable, Memory Wave memory booster and each change the same web page, every pc only sees its personal writes to the page. When the information gets 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 store pointers within the memory mapped file; retailer offsets from the base of the file mapping so that the mapping can be used at any address. ERROR exceptions, use structured exception handling to protect any code that writes to or reads from a memory mapped view of a file apart from the web page file. For extra data, see Reading and Writing From a File View. When modifying a file by way of a mapped view, the final modification timestamp will not be up to date mechanically. If required, the caller should use SetFileTime to set the timestamp. Value), the paging file should be large enough to hold the entire mapping. If it's not, MapViewOfFile fails. The preliminary contents of the pages in a file mapping object backed by the paging file are 0 (zero). RESERVE). Mapping the file makes your entire mapped digital deal with vary unavailable to different allocations in the process. After a page from the reserved vary is dedicated, it can't be freed or decommitted by calling VirtualFree. Reserved and dedicated pages are released when the view is unmapped and the file mapping object is closed. For details, see the UnmapViewOfFile and CloseHandle features.