MapViewOfFile Function Memoryapi.h

De Transcription | Bibliothèque patrimoniale numérique Mines ParisTech
Révision datée du 29 novembre 2025 à 03:49 par ValentinLeclair (discussion | contributions) (Page créée avec « <br>Maps a view of a file mapping into the handle area of a calling process. To specify a advised base deal with for the view, use the MapViewOfFileEx function. However, t... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Aller à : navigation, rechercher


Maps a view of a file mapping into the handle area of a calling process. To specify a advised base deal with for the view, use the MapViewOfFileEx function. However, this observe will not be really useful. A handle to a file mapping object. The CreateFileMapping and OpenFileMapping capabilities return this handle. The kind of entry to a file mapping object, which determines the web page safety of the pages. This parameter may be certainly one of the next values, or a bitwise OR mixture of a number of values the place appropriate. Using bitwise OR, you'll be able to combine the values above with these values. When a course of writes to a replica-on-write page, the system copies the unique page to a new page that's private to the process. The brand new web page is backed by the paging file. The protection 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 the entire view as a result of the calling course of can probably write to each page in the view, making all pages non-public.



The contents of the new web page are by no means written back to the original file and are misplaced when the view is unmapped. Home windows Server 2003 and Windows XP: This value is on the market starting with Windows XP with SP2 and Home windows Server 2003 with SP1. For extra details about access to file mapping objects, see File Mapping Security and Entry Rights. A excessive-order DWORD of the file offset where the view begins. A low-order DWORD of the file offset the place the view is to start. The combination of the excessive and low offsets should specify an offset throughout the file mapping. They should also match the virtual memory allocation granularity of the system. That is, the offset must 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 within the maximum dimension specified by CreateFileMapping. If this parameter is 0 (zero), the mapping extends from the desired offset to the tip of the file mapping.



If the function succeeds, MemoryWave Community the return worth is the beginning handle of the mapped view. If the operate fails, the return value is NULL. To get prolonged error information, name GetLastError. Mapping a file makes the required portion of a file seen within the handle house of the calling process. For information which might be larger than the tackle house, 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 new view. To acquire the size 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 an identical information at a specified time. This happens if the file views are derived from any file mapping object that is backed by the same file. A course of can duplicate a file mapping object handle into another process by using the DuplicateHandle operate, or one other course of can open a file mapping object by identify by utilizing the OpenFileMapping function.



With one necessary exception, file views derived from any file mapping object that is backed by the same file are coherent or similar at a selected time. Coherency is guaranteed for views inside a course of and for views that are mapped by totally different processes. The exception is expounded to distant files. Although MapViewOfFile works with remote files, it does not keep them coherent. For example, if two computers each map a file as writable, and each change the identical page, each computer solely sees its personal writes to the page. When the info will get up to date on the disk, it's not merged. A mapped view of a file is not guaranteed to be coherent with a file that's being accessed by the ReadFile or WriteFile operate. Do not store pointers in the memory mapped file; store offsets from the base of the file mapping in order that the mapping can be utilized at any deal with. ERROR exceptions, use structured exception dealing with to guard any code that writes to or reads from a memory 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 through a mapped view, the final modification timestamp might not be updated mechanically. If required, the caller ought to use SetFileTime to set the timestamp. Value), the paging file must be massive enough to carry the whole mapping. If it's not, MapViewOfFile fails. The preliminary contents of the pages in a file mapping object backed by the paging file are zero (zero). RESERVE). Mapping the file makes the complete mapped virtual handle range unavailable to different allocations in the process. After a web page from the reserved range is dedicated, it cannot be freed or MemoryWave Community 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 functions.