MapViewOfFile Operate (Memoryapi.h)
Maps a view of a file mapping into the address house of a calling course of. To specify a recommended base deal with for the view, use the MapViewOfFileEx function. However, this apply is just not really useful. A handle to a file mapping object. The CreateFileMapping and OpenFileMapping functions return this handle. The kind of entry to a file mapping object, which determines the web page safety of the pages. This parameter can be one in all the following values, or a bitwise OR mixture of a number of values where appropriate. Using bitwise OR, you may combine 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 new page that's private to the process. The new web page is backed by the paging file. The protection of the new page adjustments from copy-on-write to read/write. When copy-on-write entry is specified, the system and course of commit charge taken is for your complete view as a result of the calling course of can potentially write to each page in the view, making all pages personal.

The contents of the brand new web page are never written back to the original file and are misplaced when the view is unmapped. Home windows Server 2003 and Windows XP: This worth is available starting with Home windows XP with SP2 and Home windows Server 2003 with SP1. For extra information about entry to file mapping objects, Memory Wave 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 start. The combination of the high and low offsets should specify an offset inside the file mapping. They must also match the virtual Memory Wave System allocation granularity of the system. That's, the offset have to be a multiple of the VirtualAlloc allocation granularity. The number 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 top of the file mapping.

If the function succeeds, the return value is the beginning address of the mapped view. If the operate fails, the return value is NULL. To get extended error information, name GetLastError. Mapping a file makes the required portion of a file visible within the handle house of the calling process. For information which can be larger than the deal with house, you can solely map a small portion of the file information at one time. When the primary view is full, you may unmap it and map a new view. To obtain the scale of a view, use the VirtualQuery perform. Multiple views of a file (or a file mapping object and its mapped file) are coherent in the event that they include similar knowledge at a specified time. This occurs 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 operate, or one other process can open a file mapping object by identify by utilizing the OpenFileMapping operate.

With one vital exception, file views derived from any file mapping object that's backed by the same file are coherent or equivalent at a specific time. Coherency is guaranteed for views inside a course of and for views which can be mapped by different processes. The exception is expounded to distant files. Although MapViewOfFile works with distant recordsdata, it doesn't keep them coherent. For instance, if two computers each map a file as writable, and each change the identical page, every laptop only 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 shouldn't be guaranteed to be coherent with a file that's being accessed by the ReadFile or WriteFile function. Do not store pointers in the memory mapped file; retailer offsets from the bottom of the file mapping in order that the mapping can be used at any address. ERROR exceptions, use structured exception dealing with to guard any code that writes to or reads from a Memory Wave mapped view of a file aside from the page file. For extra information, see Studying and Writing From a File View. When modifying a file via a mapped view, the last 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 should be large sufficient to carry your complete mapping. If it isn't, 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 the whole mapped digital address range unavailable to other allocations in the method. After a page from the reserved range is dedicated, it cannot be freed or decommitted by calling VirtualFree. Reserved and committed pages are released when the view is unmapped and the file mapping object is closed. For details, see the UnmapViewOfFile and CloseHandle features.
Поделиться
Запись добавлена • 0 просмотров

0 комментариев

Автор топика запретил добавлять комментарии