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",&(info Var->oAndS_str));
memcpy(readingS trs, &(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,read ingStrs,tOTL);
printf("tOTL = %d and oT ptr = %p\n", tOTL, readingStrs);
char *tON[tONL]; memcpy(tON,(rea dingStrs+tOTL), tONL);
printf("tONL = %d and oN ptr = %p\n", tONL,
(readingStrs+tO TL));
char *tSN[tSNL];
memcpy(tSN,(rea dingStrs+tOTL+t ONL),tSNL);
printf("tSNL = %d and sN ptr = %p\n", tSNL,
(readingStrs+tO TL+tONL));
char *tSL[tSLL];
memcpy(tSL,(rea dingStrs+tOTL+t ONL+tSNL),tSLL) ;
printf("tSLL = %d and sL ptr = %p\n", tSLL,
(readingStrs+tO TL+tONL+tSNL));
char *tID[tIDL];
memcpy(tID,(rea dingStrs+tOTL+t ONL+tSNL+tSLL), tIDL);
printf("tIDL = %d and iD ptr = %p\n", tIDL,
(readingStrs+tO TL+tONL+tSNL+tS LL));
char tMD[tMDL];
memcpy(tMD,(rea dingStrs+tOTL+t ONL+tSNL+tSLL+t IDL),tMDL);
printf("tMDL = %d and mD ptr = %p\n", tMDL,
(readingStrs+tO TL+tONL+tSNL+tS LL+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",&(info Var->oAndS_str));
memcpy(readingS trs, &(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,read ingStrs,tOTL);
printf("tOTL = %d and oT ptr = %p\n", tOTL, readingStrs);
char *tON[tONL]; memcpy(tON,(rea dingStrs+tOTL), tONL);
printf("tONL = %d and oN ptr = %p\n", tONL,
(readingStrs+tO TL));
char *tSN[tSNL];
memcpy(tSN,(rea dingStrs+tOTL+t ONL),tSNL);
printf("tSNL = %d and sN ptr = %p\n", tSNL,
(readingStrs+tO TL+tONL));
char *tSL[tSLL];
memcpy(tSL,(rea dingStrs+tOTL+t ONL+tSNL),tSLL) ;
printf("tSLL = %d and sL ptr = %p\n", tSLL,
(readingStrs+tO TL+tONL+tSNL));
char *tID[tIDL];
memcpy(tID,(rea dingStrs+tOTL+t ONL+tSNL+tSLL), tIDL);
printf("tIDL = %d and iD ptr = %p\n", tIDL,
(readingStrs+tO TL+tONL+tSNL+tS LL));
char tMD[tMDL];
memcpy(tMD,(rea dingStrs+tOTL+t ONL+tSNL+tSLL+t IDL),tMDL);
printf("tMDL = %d and mD ptr = %p\n", tMDL,
(readingStrs+tO TL+tONL+tSNL+tS LL+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
Comment