CSharedMemory, A Small Class to Share Data Via File Mapping
Posted
by Michael Schikora
on October 18th, 2001
Environment: VC6 SP4, NT4 SP6,W98 SE, W2000 SP1
With this class, only a few lines are needed to communicate with other processes. I use it from storing HWNDs,status flags up to memory resistent fifo queues.
At least one process should keep the memory open. The CSharedMemory as a Member of CMyClass
class CMyClass
{
public:
CSharedMemory m_sm;
MyDataSruct* m_pData;
Initialisation in the constructor of CMyClass with a system wide unique name for this memory block.
CMyClass::CMyClass(..)
{
m_sm.Init("MyUniqueMemoryName",sizeof(MyDataSruct));
m_pMyData = (MyDataSruct*)m_sm.GetData();
//maybe if it is the first process
if( ! m_sm.AlreadyExist())
ZeroMemory(m_pMyData,sizeof(MyDataSruct));
Using synchronisation:
{
CSharedMemory::Locker lock(m_sm);
DoSomethingWith(m_pData);
}
//or wait only 100 milliseconds
if( m_sm.Lock( 100 ) )
{
DoSomethingWith(m_pData);
m_sm.Unlock();
}
And because I'm lazy, somtimes I use only this:
CSharedMemory sm("MyUniqueMemoryName",sizeof(MyDataSruct));
((MyDataSruct*)sm.GetData())->m_nMyMember = 123;
Downloads
Download demo project - 13 KbThe latest versions may be found at:
www.schikos.de

Comments
Infrequent review gives you the basic truth on nike which experts state just a few persons know of.
Posted by icoppyapedcap on 04/25/2013 10:39amCnyXqpMdoLiu [url=http://www.nikeyasuijp.com/]ãã¤ã[/url]WgfKzdPpsWgh [url=http://www.nikeyasuijp.com/nike-air-force1ã¨ã¢ãã©ã¼ã¹1-c-14.html]ãã¤ã ã¨ã¢ãã©ã¼ã¹[/url]RqfIkdKdwBob [url=http://www.nikeyasuijp.com/nike-air-maxã¨ã¢ããã¯ã¹-c-12.html]ãã¤ã ã¨ã¢ããã¯ã¹[/url]QovNnkZtrLrr [url=http://www.nikeyasuijp.com/nike-air-jordanã¨ã¢-ã¸ã§ã¼ãã³-c-13.html]nike air jordan[/url]IseXumEyrOqp
ReplyWill CreateFileMapping always create physical storage in memory?
Posted by Legacy on 10/29/2001 12:00amOriginally posted by: soichi
Will CreateFileMapping always create physical storage for the mapped view on memory? Otherwise, should I expect that there will be any disk access involved? I really don't know anything about the FileMapping, and my feeling is that CreateFileMapping will NEVER access to disk.. but what is the truth?
ReplyUpdate at www.schikos.de
Posted by Legacy on 10/25/2001 12:00amOriginally posted by: Michael Schikora
www.schikos.de/MFC.html
The new code is without the Memory Leak Al discribes.
Al, Thanks again !
Schiko
ReplyMemory and Resource Leak
Posted by Legacy on 10/24/2001 12:00amOriginally posted by: Al Dinelt
ReplyWell..nice try..but not very useful
Posted by Legacy on 10/22/2001 12:00amOriginally posted by: Sach
Well..it was a good try but did not solve much purpose..Cheers-Sach
ReplyReference counting
Posted by Legacy on 10/19/2001 12:00amOriginally posted by: P. Kramer
You could add reference counting to the shared memory
block, an often used mechanism when you have shared
resources.
If you add a reference count to the shared memory block
Replyyou have a bit more control to the life-time of the block.
As long as one client is using the memory block you can
keep it alive.