Home > Software engineering >  The memory mapping file and # pragma data_seg (" YCIShared ")
The memory mapping file and # pragma data_seg (" YCIShared ")

Time:11-11

Shared data area:
The # pragma data_seg (" YCIShared ")
HWND g_hWndCaller=NULL;
HHOOK g_hHook=NULL;
# pragma data_seg ()

The memory mapping file:
The class CShareMemory
{
Public:
//the constructor and destructor
CShareMemory (const char * pszMapName, int nFileSize=0, BOOL bServer=FALSE).
~ CShareMemory ();
//attribute
Const LPVOID GetBuffer () {return m_pBuffer; }
//implementation
Private:
HANDLE m_hFileMap;
LPVOID m_pBuffer;
};

The inline CShareMemory: : CShareMemory (const char * pszMapName,
Int nFileSize, BOOL bServer) : m_hFileMap (NULL), m_pBuffer (NULL)
{
If (bServer)
{
//create a memory mapped file object
M_hFileMap=CreateFileMapping (INVALID_HANDLE_VALUE,
NULL, PAGE_READWRITE, 0, nFileSize, pszMapName);
}
The else
{
//open a memory mapped file object
M_hFileMap=OpenFileMapping (FILE_MAP_ALL_ACCESS, FALSE, pszMapName);
}

//map it into memory, the head of the Shared memory address
M_pBuffer=(LPBYTE) MapViewOfFile (
M_hFileMap,
FILE_MAP_ALL_ACCESS,
0,
0,
0
);
}

The inline CShareMemory: : ~ CShareMemory ()
{
//cancel the file mapping, close the file mapping object handle
UnmapViewOfFile (m_pBuffer);
The CloseHandle (m_hFileMap);
}
-
The great god, please what is the difference between the two

CodePudding user response:

# pragma data_seg generally use defined in the DLL Shared data segment, all articulated the DLL process can access the same data segment
Naming the file mapping also can be Shared, but access process can have no correlation between

CodePudding user response:

reference 1st floor zgl7903 response:
# pragma data_seg generally use defined in the DLL Shared data segment, all articulated the DLL process can access the same data segment
Naming the file mapping also can be Shared, but the process of access can have no correlation between

The details are know much predecessors
  • Related