N
nass
hello everyone, i have a bit of problem reading char * strings from a
buffer (a shared memory, pointed to by 'file_memory').
basically i have a structure in memory 'ShMem' that can be accessed by
2 applications (or will be at least when it is done).
the structure is declared in the procedure under the pointer infoVar.
members tXXL are integer lengths of the strings that as all saved
(concatenated) at address of oAndS_str, which is of type char.
i do not get the right values back however, and i wonder if the tXX
'reconstruction strings' are assigned values properly with memcpy.
void readingTheShMem()
{
int tOTL=0;
int tONL=0;
int tSNL=0;
int tSLL=0;
int tIDL=0;
int tMDL=0;
int readingLength;
//lock the file for writing
memset (&lock, 0, sizeof(lock));
lock.l_type = F_WRLCK;
fcntl (fd, F_SETLKW, &lock);
struct ShMem *infoVar=(ShMem*)((char*)file_memory);
tOTL = infoVar->oTL;
tONL = infoVar->oNL;
tSNL = infoVar->sNL;
tSLL = infoVar->sLL;
tIDL = infoVar->iDL;
tMDL = infoVar->mDL;
readingLength = tOTL + tONL + tSNL + tSLL + tIDL + tMDL ;
char *readingStrs[readingLength];
printf("reading length = %d\n", readingLength);
printf("the infoVar->oAndS_str reading points
to=%p\n",&(infoVar->oAndS_str));
memcpy(readingStrs, &(infoVar->oAndS_str),
readingLength);
//unlock the file to allow access
lock.l_type = F_UNLCK;
fcntl (fd, F_SETLKW, &lock);
char *tOT[tOTL]; memcpy(tOT,readingStrs,tOTL);
printf("tOTL = %d and oT ptr = %p\n", tOTL, readingStrs);
char *tON[tONL]; memcpy(tON,(readingStrs+tOTL),tONL);
printf("tONL = %d and oN ptr = %p\n", tONL,
(readingStrs+tOTL));
char *tSN[tSNL];
memcpy(tSN,(readingStrs+tOTL+tONL),tSNL);
printf("tSNL = %d and sN ptr = %p\n", tSNL,
(readingStrs+tOTL+tONL));
char *tSL[tSLL];
memcpy(tSL,(readingStrs+tOTL+tONL+tSNL),tSLL);
printf("tSLL = %d and sL ptr = %p\n", tSLL,
(readingStrs+tOTL+tONL+tSNL));
char *tID[tIDL];
memcpy(tID,(readingStrs+tOTL+tONL+tSNL+tSLL),tIDL);
printf("tIDL = %d and iD ptr = %p\n", tIDL,
(readingStrs+tOTL+tONL+tSNL+tSLL));
char tMD[tMDL];
memcpy(tMD,(readingStrs+tOTL+tONL+tSNL+tSLL+tIDL),tMDL);
printf("tMDL = %d and mD ptr = %p\n", tMDL,
(readingStrs+tOTL+tONL+tSNL+tSLL+tIDL));
printf("oT = %s\n",tOT);
printf("oN = %s\n",tON);
printf("sN = %s\n",tSN);
printf("sL = %s\n",tSL);
printf("iD = %s\n",tID);
printf("mD = %s\n",tMD);
//do smth with these variables now
}
any ideas where my c++ knowledge is slipping?
thank you for your help
nass
buffer (a shared memory, pointed to by 'file_memory').
basically i have a structure in memory 'ShMem' that can be accessed by
2 applications (or will be at least when it is done).
the structure is declared in the procedure under the pointer infoVar.
members tXXL are integer lengths of the strings that as all saved
(concatenated) at address of oAndS_str, which is of type char.
i do not get the right values back however, and i wonder if the tXX
'reconstruction strings' are assigned values properly with memcpy.
void readingTheShMem()
{
int tOTL=0;
int tONL=0;
int tSNL=0;
int tSLL=0;
int tIDL=0;
int tMDL=0;
int readingLength;
//lock the file for writing
memset (&lock, 0, sizeof(lock));
lock.l_type = F_WRLCK;
fcntl (fd, F_SETLKW, &lock);
struct ShMem *infoVar=(ShMem*)((char*)file_memory);
tOTL = infoVar->oTL;
tONL = infoVar->oNL;
tSNL = infoVar->sNL;
tSLL = infoVar->sLL;
tIDL = infoVar->iDL;
tMDL = infoVar->mDL;
readingLength = tOTL + tONL + tSNL + tSLL + tIDL + tMDL ;
char *readingStrs[readingLength];
printf("reading length = %d\n", readingLength);
printf("the infoVar->oAndS_str reading points
to=%p\n",&(infoVar->oAndS_str));
memcpy(readingStrs, &(infoVar->oAndS_str),
readingLength);
//unlock the file to allow access
lock.l_type = F_UNLCK;
fcntl (fd, F_SETLKW, &lock);
char *tOT[tOTL]; memcpy(tOT,readingStrs,tOTL);
printf("tOTL = %d and oT ptr = %p\n", tOTL, readingStrs);
char *tON[tONL]; memcpy(tON,(readingStrs+tOTL),tONL);
printf("tONL = %d and oN ptr = %p\n", tONL,
(readingStrs+tOTL));
char *tSN[tSNL];
memcpy(tSN,(readingStrs+tOTL+tONL),tSNL);
printf("tSNL = %d and sN ptr = %p\n", tSNL,
(readingStrs+tOTL+tONL));
char *tSL[tSLL];
memcpy(tSL,(readingStrs+tOTL+tONL+tSNL),tSLL);
printf("tSLL = %d and sL ptr = %p\n", tSLL,
(readingStrs+tOTL+tONL+tSNL));
char *tID[tIDL];
memcpy(tID,(readingStrs+tOTL+tONL+tSNL+tSLL),tIDL);
printf("tIDL = %d and iD ptr = %p\n", tIDL,
(readingStrs+tOTL+tONL+tSNL+tSLL));
char tMD[tMDL];
memcpy(tMD,(readingStrs+tOTL+tONL+tSNL+tSLL+tIDL),tMDL);
printf("tMDL = %d and mD ptr = %p\n", tMDL,
(readingStrs+tOTL+tONL+tSNL+tSLL+tIDL));
printf("oT = %s\n",tOT);
printf("oN = %s\n",tON);
printf("sN = %s\n",tSN);
printf("sL = %s\n",tSL);
printf("iD = %s\n",tID);
printf("mD = %s\n",tMD);
//do smth with these variables now
}
any ideas where my c++ knowledge is slipping?
thank you for your help
nass