Introduction

About Shared Memory

When a program loads into the memory, it is broken up into pieces called pages. The communication would exist between the pages of memory or between two independent processes. Anyhow, when a program would like to communicate with another, there should be a common area in the memory for both the programs. This area which is shared between processes is called the Shared Memory. If there was no concept of shared memory, the section of memory occupied by a program could not be accessed by another one thus disabling the concept of sharing data or communication. Then again, in order to reduce integrity of shared data and to avoid concurrent access to the data, kernel provides a mechanism to exclusively access the shared memory resource. This is called mutual exclusion or mutex object.

When a process wants to communicate to another, the following steps take place sequentially:

Take the mutex object, locking the shared area.

Write the data to be communicated into the shared area.

Release the mutex object.

When a process reads from the area, it should repeat the same steps, except that the step 2 should be Read.

<A name=#code>

About the Code

In order for the program to communicate, the shared memory region should be made when the program starts, at least in this case. This is done by using the following code in the OnCreate function mapped for WM_CREATE message. (You can do this explicitly by adding a handler for WM_CREATE by ClassWizard). Before doing that, write down the global variables (outside any class) as follows:

All these things can be defined in the header file for the implementation file of the shared memory. It can be a dialog box or a document interface.

Share

About the Author

I am a personality from Trivandrum , a green peaceful place in Kerala, South India.I have been an enthusiast of Windows programming when I started creating simple windows when I learnt VC++ in LCC in Trivandrum. From then on its all about Windows in my flesh and blood. My career graph moves like this:1. I started working as a C/C++ programmer in a company in Trivandrum where I learnt the ABCs of Software Industry. I worked with them for about 1 year. I could not contine since I was in contract for 1 year. 2. Then I joined another organization in Trivandrum who gave me challenges to love. They made me mad about VC++ and Windows.I was mad about Embedded Systems which made me, Myself = Embedded Systems + VC++.3. Software Engineer in a telecom company in Hyderabad, Andhra Pradesh, S.India.4. Currently working with a telecom company in Bangalore.I totally, so, have experience of about 4.5 years.