473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

problems with saving strings in a shared memory segment

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..

Oct 5 '06 #1
1 2419
nass wrote:
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-lit....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-lit...alization.html

and check out Boost.Serialization:

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

Cheers! --M

Oct 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim | last post by:
I'm using the shmop_* functions to create and access shared memory. I've never used shared memory before, so I apologize if my reasoning is completely off... $shm_id = shmop_open(ftok(__FILE__,...
3
by: alanrn | last post by:
I would like to start a dialog on how to implement the equivalent functionality of UNIX shared memory in .NET. I work with a factory automation system. The bulk of the system is written in C/C++....
18
by: John DeSoi | last post by:
I get this when I try to start up a freshly compiled beta4 on OS X 10.2.6: FATAL: could not create shared memory segment: Invalid argument I saw a previous thread on this for beta2. It...
4
by: Lafer | last post by:
Hello, I am attempting to write a terminal interface program using PowerPC Assembly/C, where I am using an integer-to-ASCII conversion algorithm. Unfortunately, I have run into some difficulties...
1
by: Alexander Cohen | last post by:
Hi, sometimes ill get this error: FATAL: could not create shared memory segment: Cannot allocate memory DETAIL: Failed system call was shmget(key=2, size=4153344, 03600). HINT: This error...
7
by: nass | last post by:
hi all, i am running slackware linux and need to use some function that will will enable me to write and read from a shared mem segment.. i am using open() , to open a file, and then use mmap to...
2
by: zeny | last post by:
Hi everybody! In the file "server.c" i created a shared memory segment of the size of a 1024 byte string and then i attached a string to the segment, just like this: int key = 12345; char...
1
by: zeny | last post by:
Hey everyone! I´ve been tying to create a shared memory segment with the size of a structure, as follows: typedef struct{ int id; char message; }data; In the line where i create the shared...
2
by: oopsatwork | last post by:
Ok...so, I have been outside of the C world for a _very_ long time...but not so long as to remember how to do multidimensional arrays. So, let me state that I know how to malloc pointers to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.