Using Memory-Mapped Files

To use a memory-mapped file, you must perform three steps:

  1. Create or open a file kernel object that identifies the file on disk that you want to use as a memory-mapped file.

  2. Create a file-mapping kernel object that tells the system the size of the file and how you intend to access the file.

  3. Tell the system to map all or part of the file-mapping object into your process’ address space.

When you are finished using the memory-mapped file, you must perform three steps to clean up:

  1. Tell the system to unmap the file-mapping kernel object from your process’ address space.

  2. Close the file-mapping kernel object.

  3. Close the file kernel object.

The next five sections discuss all these steps in more detail.

Step 1: Creating or Opening a File ...

Get Windows® via C/C++, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.