Export (0) Print
Expand All
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Memory Mapping a File

Windows CE 3.0

Memory-mapping allows access to a file though a memory object that is mapped directly to the file. Memory-mapped files provide a method both for interprocess communication, and as a way to allocate virtual memory regions larger than the 32MB slot size limit.

While memory mapping is somewhat more complicated to set up than traditional memory access it simplifies file access by eliminating the need for a system-maintained pointer for read and write operations. Changes are written directly to memory and Windows CE reflects any change to the memory-mapped object back to the file.

To set up and access a file by using memory mapping

  1. Call the CreateFileForMapping function to open or create the memory-mapped file. If a single file is to be shared between applications, then only one application should call CreateFileForMapping. All other applications should skip to step 2.

    You can open any file, including files that are created by the CreateFile function, for memory mapping. For Windows CE 2.10 and earlier, you can use CreateFileForMapping for read-only permission.

  2. Use the CreateFileMapping function to create an object in memory and to tie the object to the file that is opened by the CreateFileForMapping function.
  3. Use the MapViewOfFile function to create a view of the memory-mapped object.
  4. Use the pointer that is returned by the MapViewOfFile function to gain direct access to the memory-mapped object.
  5. Call the UnmapViewOfFile function to unmap the object view.
  6. Call the CloseHandle function to close the memory object.
  7. Call the CloseHandle function to close the file.

© 2014 Microsoft