problems with saving strings in a shared memory segment

N

nass

hello everyone.. i am not sure what is wrong - never liked strings
anyway!
my problem is that i am trying to save a QCstring in a shared memory
segment and i get a segmentation fault..
here is the case statement that causes the trouble.. i could post the
whole procedure but there is no point. similar case statements as the
following one exisst in the procedure that save in the same memory
segment (but at dif offest) floats, Q_UINT8 and other non string type
of variables.

case 4: //the scheduler capacitors are calling
{
struct schedStruct {
Q_UINT8 c1TD;
Q_UINT8 c2TD;
Q_UINT8 c3TD;
QCString c1OnDate;
QCString c2OnDate;
QCString c3OnDate;
QCString c1OffDate;
QCString c2OffDate;
QCString c3OffDate;
};

//lock the file for writing
memset (&lock, 0, sizeof(lock));
lock.l_type = F_WRLCK;
fcntl (fd, F_SETLKW, &lock);
printf("locked the file\n");

*((char*)file_memory+opcodeOffset) = 4;
struct schedStruct *schedVar=(schedStruct*)((char*)file_memory +
0xCC);
schedVar->c1TD=c1TimerDaily;
schedVar->c2TD=c2TimerDaily;
schedVar->c3TD=c3TimerDaily;
printf("done with dailys\n");
schedVar->c1OnDate=(c1TimerOnDate.local8Bit());
printf("done with qcstring1On\n");
schedVar->c2OnDate=c2TimerOnDate.local8Bit();
schedVar->c3OnDate=c3TimerOnDate.local8Bit();
schedVar->c1OffDate=c1TimerOffDate.local8Bit();
schedVar->c2OffDate=c2TimerOffDate.local8Bit();
schedVar->c3OffDate=c3TimerOffDate.local8Bit();
printf("saved them");

//unlock the file to allow access
lock.l_type = F_UNLCK;
fcntl (fd, F_SETLKW, &lock);
printf("unlocked\n");



file_memory is void* to the beginning of the sh.mem.segment.
cXTimerDaily are unsigned chars
and
cXTimerOnDate, cXTimerOffDate are normal 16bit QStrings containing a
date in the form:
'08:00 - 01/01/2006' - ie just ascii chars therefore i should have no
problem doing conversion to 8bit strings (as QCStrings are)..
anyway,
i run the gdb and i can get up to the line '
schedVar->c1OnDate=(c1TimerOnDate.local8Bit());'
(between the 2 printf() lines).
then i use the next command. here is as far as i get :

877 printf("done with dailys\n");
(gdb) next
done with dailys
249 { return (QCString&)assign( s ); }
(gdb) next
79 { return (QMemArray<type>&)QGArray::assign(a); }
(gdb) next

Program received signal SIGSEGV, Segmentation fault.
0xb7df1098 in QGArray::assign () from /usr/lib/qt/lib/libqt-mt.so.3
(gdb)



any ideas how to tackle this?
nass

ps. somebody told me to 'serialise' data that are to be used by other
processes or else the pointers to these data 'will mean nothing tothe
other process'... but i do not know how t serialise string data... or
anydata whatsoever..
 
M

mlimber

nass said:
hello everyone.. i am not sure what is wrong - never liked strings
anyway!
my problem is that i am trying to save a QCstring in a shared memory
segment and i get a segmentation fault..
here is the case statement that causes the trouble.. i could post the
whole procedure but there is no point. similar case statements as the
following one exisst in the procedure that save in the same memory
segment (but at dif offest) floats, Q_UINT8 and other non string type
of variables.

case 4: //the scheduler capacitors are calling
{
struct schedStruct {
Q_UINT8 c1TD;
Q_UINT8 c2TD;
Q_UINT8 c3TD;
QCString c1OnDate;
QCString c2OnDate;
QCString c3OnDate;
QCString c1OffDate;
QCString c2OffDate;
QCString c3OffDate;
};

//lock the file for writing
memset (&lock, 0, sizeof(lock));
lock.l_type = F_WRLCK;
fcntl (fd, F_SETLKW, &lock);
printf("locked the file\n");

*((char*)file_memory+opcodeOffset) = 4;
struct schedStruct *schedVar=(schedStruct*)((char*)file_memory +
0xCC);
schedVar->c1TD=c1TimerDaily;
schedVar->c2TD=c2TimerDaily;
schedVar->c3TD=c3TimerDaily;
printf("done with dailys\n");
schedVar->c1OnDate=(c1TimerOnDate.local8Bit());
printf("done with qcstring1On\n");
schedVar->c2OnDate=c2TimerOnDate.local8Bit();
schedVar->c3OnDate=c3TimerOnDate.local8Bit();
schedVar->c1OffDate=c1TimerOffDate.local8Bit();
schedVar->c2OffDate=c2TimerOffDate.local8Bit();
schedVar->c3OffDate=c3TimerOffDate.local8Bit();
printf("saved them");

//unlock the file to allow access
lock.l_type = F_UNLCK;
fcntl (fd, F_SETLKW, &lock);
printf("unlocked\n");



file_memory is void* to the beginning of the sh.mem.segment.
cXTimerDaily are unsigned chars
and
cXTimerOnDate, cXTimerOffDate are normal 16bit QStrings containing a
date in the form:
'08:00 - 01/01/2006' - ie just ascii chars therefore i should have no
problem doing conversion to 8bit strings (as QCStrings are)..
anyway,
i run the gdb and i can get up to the line '
schedVar->c1OnDate=(c1TimerOnDate.local8Bit());'
(between the 2 printf() lines).
then i use the next command. here is as far as i get :

877 printf("done with dailys\n");
(gdb) next
done with dailys
249 { return (QCString&)assign( s ); }
(gdb) next
79 { return (QMemArray<type>&)QGArray::assign(a); }
(gdb) next

Program received signal SIGSEGV, Segmentation fault.
0xb7df1098 in QGArray::assign () from /usr/lib/qt/lib/libqt-mt.so.3
(gdb)



any ideas how to tackle this?

You might ask in a forum dedicated to Qt or your platform. Shared
memory and the Qt library are both off-topic in this newsgroup which
deals with platform-independent, standard C++
(http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9).
ps. somebody told me to 'serialise' data that are to be used by other
processes or else the pointers to these data 'will mean nothing tothe
other process'... but i do not know how t serialise string data... or
anydata whatsoever..

See these FAQs:

http://www.parashift.com/c++-faq-lite/serialization.html

and check out Boost.Serialization:

http://boost.org/libs/serialization/doc/index.html

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top