|This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.|
A memory-mapped file, or file mapping, is the result of associating file contents with a portion of the virtual address space of a process. It can be used to share a file or memory between two or more processes.
File-mapping objects are not necessarily backed by a file on the disk. You can create a file mapping by passing an open file handle to CreateFileMapping. The data in the mapping is paged back and forth between RAM and the file as you access the mapping. This type of mapping is called a file-backed mapping. You can also create a file mapping without using a file handle. In such a case, the data in the mapping resides entirely in RAM and is never paged out. This type of mapping is called a RAM-backed mapping.
You can use named memory-mapped files as a method of interprocess communication. If you give the file-mapping object a name, other processes can use the name to open handles to the same mapping object. If you do not give the file-mapping object a name, the only way another process can access the mapping is if you use DuplicateHandleto make a new handle to the mapping and pass the handle to the other process.
Keep the following in mind when working with memory-mapped files:
- Information in a readable memory-mapped file can be read by
other processes on the system. Do not store confidential
information in a memory-mapped file.
- Information in a writeable memory mapped file can be written to
by other processes on the system. You must validate all data that
you read from a memory mapped file.