Windows list memory mapped files




















The GetMappedFileName function receives a process handle and a pointer to an address as input. If the address is within a memory-mapped file in the virtual address space of the process, the function returns the name of the memory-mapped file. The file names returned by GetMappedFileName use device form, rather than drive letters. For more information about memory-mapped files, see File Mapping.

For an example that converts file names in device form to drive letters, see Obtaining a File Name From a File Handle. This is not to say that memory-mapped files are without disadvantages. But there are a great many cases when memory-mapped files can be extremely effective, and these are often overlooked by Windows developers.

Section objects are also used to share memory between processes. When one process names a section object, another process may open a handle to it by using the same name given the appropriate access rights. Both processes can then map regions of that section object to their respective virtual address spaces. After both processes have done so, each process will have a region of virtual memory pages mapped to the shared region of physical memory pages.

Note that the section object might be based on a file on disk, in which case you have a memory-mapped file shared across processes: this is what the OS image loader does with DLLs. Or, the section object may not be based on a file on disk, in which case it is purely a shared memory region backed by the page file, if present. Neither your application nor the CPU has to care whether the memory pages are shared with another process or not. Thanks for visiting DZone today,. Edit Profile. It also allows the process to work efficiently with a large data file, such as a database, without having to map the whole file into memory.

Multiple processes can also use memory-mapped files to share data. Processes read from and write to the file view using pointers, just as they would with dynamically allocated memory. The use of file mapping improves efficiency because the file resides on disk, but the file view resides in memory.

Processes can also manipulate the file view with the VirtualProtect function. The following illustration shows the relationship between the file on disk, a file mapping object, and a file view. The file on disk can be any file that you want to map into memory, or it can be the system page file. The file mapping object can consist of all or only part of the file. It is backed by the file on disk. This means that when the system swaps out pages of the file mapping object, any changes made to the file mapping object are written to the file.



0コメント

  • 1000 / 1000