Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 26th, 2008, 7:02 PM   #1
SAWG
Newbie
 
Join Date: Apr 2008
Posts: 1
Rep Power: 0 SAWG is on a distinguished road
structure with an array in shared memory

Hi. I'm having difficulties with shared memory.
I have a structure which looks like this:
c Syntax (Toggle Plain Text)
  1. struct sharemem{
  2. int *actual
  3. int *end;
  4. int *sharearr;
  5. }
I use shmget (IPC_PRIVATE, sizeof(struct sharemem), IPC_CREAT | 0777) to get an ID.
Afterwards I use fork(), the child jumps into a function which attaches the shared memory ID of the structure, mallocs the *sharearr pointer(I pass on the size to the function via an argument),and fills it with integers ranging from 1 to (size+1).
The problem comes up when I try to access the array with the parent function(the parent is suspended until the child is done filling the array). The pointers seem to be actually shared, I just can't get access to any of the members of the array.
Could someone please tell me what I'm doing wrong?
SAWG is offline   Reply With Quote
Old Apr 28th, 2008, 12:24 AM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
Re: structure with an array in shared memory

I haven't used shmget, but I would imagine you need to allocate the sharearr array using smget as well. This means that your structure would need to contain the sharearr id rather than the pointer. Then your calling process would have to call shmat to get a pointer to the memory.
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
queue - shared memory programmingnoob C++ 4 Mar 26th, 2007 8:19 PM
dynamic array of structure pointer atogrev C 7 Oct 27th, 2006 2:23 PM
Masm rsnd Assembly 4 May 20th, 2006 9:05 PM
address memory in an array b1g4L C++ 9 Feb 5th, 2006 2:33 AM
Installing IPB 2.03 bh4575 Other Web Development Languages 0 Apr 23rd, 2005 2:36 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:28 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC