Memory Mapped Files

This article is intended to extend the idea of Inter Process Communication with a Memory Mapped File object by using a class that handles that memory object (or any memory) as a memory pool, a "heap". This class, CAllocationHandler, creates a layout of that memory consisting of a header, an allocation table, and a memory area where the allocated memory blocks resides. Those memory blocks may be moved by the class during the allocation/deallocation calls, so the memory blocks are mainly handled using "memory handles".

To directly access a memory block, it must be locked through this handle. The memory handle can also be transferred between processes that uses the same Memory Mapped File object and used to access the data.

The archive AllocationHandler_src contains the class files
  • AllocationHandler.h
  • AllocationHandler.cpp
  • AllocationHandler.inl
and the article (a plain text file)
  • AllocationHandler.txt
The archive AllocationHandler_demo contains a simple Console application that demonstrates the use of CAllocationHandler by simulating two producer threads of data allocated on the "heap", then saving the memory handles in a CList that is periodically checked by a consumer thread.

Downloads

Download demo project - 7 Kb
Download source - 15 Kb


Comments

  • Deadlocks!

    Posted by Legacy on 02/16/2004 12:00am

    Originally posted by: Raymond Lee

    The code seems to deadlock all the time on my machine (Win2K Pro). I haven't tried to debug it. Looks like a good piece of code otherwise!

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Mobile is introducing sweeping changes throughout your workplace. As a senior stakeholder driving mobile initiatives in your organization, you may be lost in a sea of technologies and claims from vendors promising rapid delivery of applications to your employees, customers, and partners. To help explain some of the topics you will need to be aware of, and to separate the must-haves from the nice-to-haves, this reference guide can help you with applying a mobile strategy in the context of application …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds