Click here to Skip to main content
15,886,664 members
Articles / Programming Languages / C++

A Wrapped Class of Share Memory

Rate me:
Please Sign up or sign in to vote.
3.68/5 (16 votes)
9 Jul 2007CPOL1 min read 206.4K   1.5K   26  
Share information betwwen processes using Memory-Mapped File
#pragma once
#include <string>
using std::string;
#include <map>
using std::map;
class MMF;
class SharedMemory
{
/************************************************************************/
/* 
the class SharedMemory uses the Singleton pattern
* @author Bony.Chen
* @description
				the SharedMemory object can contain multiple memory-mapped
				file objects and one MMF object has special name.the object
				is implemented using Singleton pattern.
* @mail bonyren@163.com
*/
/************************************************************************/
protected:
	SharedMemory();
private:
	SharedMemory(const SharedMemory& sm)
	{

	}
	SharedMemory& operator= (const SharedMemory& sm)
	{

	}
public:
	virtual ~SharedMemory(void);
public:
	///Get the only instance object
	static SharedMemory& Instance();
	///write data to the special MMF that named 'szName'
	bool WriteSharedMemory(const string& szName,const string& szValue);
	///read data from the special MMF that named 'szName'
	bool ReadSharedMemory(const string& szName,string& szValue);
	///delete the special MMF that named 'szName'
	void DeleteSharedMemory(const string& szName);
private:
	map<string,MMF*> m_mapMMF;//<the container of MMFs
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
China China
Bony Chen, a senior software engineer, specializes in C++, COM, C#, ASP.net, ISAPI. He has nearly seven years of software development experience, and has successfully developed many influential software products, such as SPES, CSO, QQ (a famous IM tool in China).
And now he is focusing on P2P technology. He aims at being an expert in software development, software consulting, software components and computer science.
If you have any opinions or questions in software area, please contact bonyren@163.com.

Comments and Discussions