473,662 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_m emory+opcodeOff set) = 4;
struct schedStruct *schedVar=(sche dStruct*)((char *)file_memory +
0xCC);
schedVar->c1TD=c1TimerDa ily;
schedVar->c2TD=c2TimerDa ily;
schedVar->c3TD=c3TimerDa ily;
printf("done with dailys\n");
schedVar->c1OnDate=(c1Ti merOnDate.local 8Bit());
printf("done with qcstring1On\n") ;
schedVar->c2OnDate=c2Tim erOnDate.local8 Bit();
schedVar->c3OnDate=c3Tim erOnDate.local8 Bit();
schedVar->c1OffDate=c1Ti merOffDate.loca l8Bit();
schedVar->c2OffDate=c2Ti merOffDate.loca l8Bit();
schedVar->c3OffDate=c3Ti merOffDate.loca l8Bit();
printf("saved them");

//unlock the file to allow access
lock.l_type = F_UNLCK;
fcntl (fd, F_SETLKW, &lock);
printf("unlocke d\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=(c1Ti merOnDate.local 8Bit());'
(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&)assi gn( s ); }
(gdb) next
79 { return (QMemArray<type >&)QGArray::ass ign(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 2441
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_m emory+opcodeOff set) = 4;
struct schedStruct *schedVar=(sche dStruct*)((char *)file_memory +
0xCC);
schedVar->c1TD=c1TimerDa ily;
schedVar->c2TD=c2TimerDa ily;
schedVar->c3TD=c3TimerDa ily;
printf("done with dailys\n");
schedVar->c1OnDate=(c1Ti merOnDate.local 8Bit());
printf("done with qcstring1On\n") ;
schedVar->c2OnDate=c2Tim erOnDate.local8 Bit();
schedVar->c3OnDate=c3Tim erOnDate.local8 Bit();
schedVar->c1OffDate=c1Ti merOffDate.loca l8Bit();
schedVar->c2OffDate=c2Ti merOffDate.loca l8Bit();
schedVar->c3OffDate=c3Ti merOffDate.loca l8Bit();
printf("saved them");

//unlock the file to allow access
lock.l_type = F_UNLCK;
fcntl (fd, F_SETLKW, &lock);
printf("unlocke d\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=(c1Ti merOnDate.local 8Bit());'
(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&)assi gn( s ); }
(gdb) next
79 { return (QMemArray<type >&)QGArray::ass ign(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.Serializa tion:

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
5387
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__, 'a'), "c", 0600, 32); That works for the first process, but if I try to launch a second process it gives me the warning "Unable to create or attach shared memory" and fails. According to the PHP manual, the 'c' flag will create shared memory,...
3
2135
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++. It was ported from UNIX to run under Windows using .NET. If for no other reason than as an educational exercise, I have been wondering what it would take to rewrite the system under C#. The system currently has about a 100K “shared...
18
2956
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 sounded like this was a bug that was to be fixed in beta3, but I'm still having this problem with beta4. Thanks,
4
1409
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 that seem to deal with the syntax/character types that am I using. Below is a segment of my code which is intended to convert an integer to an array of ASCII digits: > > char * inttoascii(int val)
1
3158
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 usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space. To reduce the request size (currently 4153344 bytes), reduce PostgreSQL's shared_buffers parameter (currently 400) and/or its...
7
2829
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 get a void* file_memory pointer. then i use fwrite(aStruct,structSize,1,(((FILE*) file_memory) + anOffset)) to try to write to the file but it crashes. could it be that fwrite does not understand the file_memory pointer? what else can i use to...
2
2245
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 *message = "hello_world"; if((shmid = shmget(key, sizeof(char)*1024, IPC_CREAT | 0666)) < 0){ perror("Error in shmget()!"); exit(1);
1
1864
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 memory segment, if((shmid = shmget(key, sizeof(data), 0766 | IPC_CREAT)) < 0){
2
4482
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 pointers and then malloc my data space. This question is NOT about that. I need to keep a dynamically sized (a result of command line options) matrix in a shared memory segment created via shmget and attached via shmat. My first instinct was to do...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8762
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.