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

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

  • The first phase of API management was about realizing the business value of APIs. This next wave of API management enables the hyper-connected enterprise to drive and scale their businesses as API models become more complex and sophisticated. Today, real world product launches begin with an API program and strategy in mind. This API-first approach to development will only continue to increase, driven by an increasingly interconnected web of devices, organizations, and people. To support this rapid growth, …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds