다음을 통해 공유


Memory Mapping a File (Windows CE 5.0)

Send Feedback

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 32-MB 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.

Security Note   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.

To set up and access a file 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. Otherwise, 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.

See Also

File System Operations

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.