Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shared Memory

Status
Not open for further replies.

sajiv77

Programmer
Jan 2, 2002
14
IN
Hi
I want to populate a number in the Shared Memory of Linux.
Iam doing the following
This is my header file which contains the Shared memory structures

#ifndef _DATABASE_SHARED_
#define _DATABASE_SHARED_

typedef struct
{
char m_sTransactionNo[15];

} DBShared;
#define _SHM_KEY (key_t)0x100
#define _SHM_SZ sizeof(_SHM)

#endif
----------------------------------------------------
This function gets the shared memory

DBShared * GetDBSharedMemory()
{
static DBShared * pSharedMemory = NULL;

if (!pSharedMemory)
{
int nShmID = shmget( _SHM_KEY, _SHM_SZ, 0);
if ( nShmID >= 0)
{
pSharedMemory = (DBShared*) shmat( nShmID, 0L, 0);
}
}
return pSharedMemory;
}

Now how do i populate the stucture's element m_sTransactionNo with a number which is 14 character long ex A7247274724727"

Also,how do i read the same .
Can anybody help me in writing a good c++ program for it

Thanks in advance
 
I'm a believer in the "Keep it simple stupid" school.

char* pSharedMemory;
int nShmID;
if((nShmID = shmget( _SHM_KEY,0, 0))<0)
exit(EXIT_FAILURE);

if((pSharedMemory = shmat( nShmID, 0L, 0))<(char*)0)
exit(EXIT_FAILURE);

pSharedMemory=malloc(sizeof(char)*BUFFER_SIZE)
for(int i=0;i<BUFFER_SIZE;i++)
pSharedMemory=data;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top