CMemMapFile iconCMemMapFile 1.58

An MFC class to encapsulate Memory Mapped Files
CMemMapFile was designed to be an MFC class to encapsulate Memory Mapped Files.

Memory mapping is a powerful mechanism Win32 provides to implement shared memory and also to access files though a simple memory pointer without having to implement your own home brewed buffering mechanisms. As an example its as simple as calling

void* lpData = mmf.Open();
CharUpperBuff(static_cast(lpData), static_cast(mmf.GetLength()));

to convert a file (of any length) to upper case.

Areas where you might find this of interest include very large database files with fixed records, audio processing, string operations and image processing.

The other side of memory mapped files is to implement shared memory. As you will probably know, Win32 puts each process into its own address space, thus making it impossible to pass ordinary pointers across process boundaries. With memory mapped files you get back this very useful mechanism.

last updated on:
January 30th, 2014, 0:35 GMT
file size:
36 KB
price:
FREE!
developed by:
Naughter Software
license type:
Freeware
operating system(s):
Windows All
category:
C: \ Programming \ Components & Libraries

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

What's New in This Release:
  • Updated copyright details.
  • Updated the code to clean compile on VC 2013
  • Updated the code to clean compile using /analyze
  • Reverted the code changes which made the class completely thread-safe. The issue was that you ended up with a class which had two different synchronisation primitives running in parallel throughout the class codebase. This design pattern is always bad and in this case could lead to thread deadlock situations in some situations. Similar to the MFC thread synchronisation primitives design patterns, an instance of the CMemMapFile class should only be used from the one thread. If you want to use the same logical memory mapped file from multiple threads in your application, then create a second instance and simple call the MapFile, MapMemory or MapExistingMemory methods to get access to the mapping. See the "MoniterSM" worker thread in testmemmap.cpp in the sample app on how to do this correctly. Thanks to "jianhongsong" for reporting this issue.
read full changelog

Add your review!

SUBMIT