The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[C] Problems with shared memory hurricane86 High Level Programming 2 11-26-2008 05:58 PM
Shared memory for shared library otheus High Level Programming 0 09-03-2008 04:55 AM
Shared memory in shared library DreamWarrior High Level Programming 12 05-30-2007 05:33 PM
memory sharing - not shared memory - elzalem High Level Programming 9 05-02-2007 08:45 AM
Shared memory shortage but lots of unused memory cjcamaro UNIX for Advanced & Expert Users 1 10-13-2004 06:10 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-28-2009
BeNdErR BeNdErR is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 4
Problems with shared memory and lists

Hi, I need to put in shared memory a list made with object of this structure:

Code:
typedef struct Obj{
char objname[20];
struct Obj *nextObj;
}Object
I've filled my list with (for example) 10 elements, but when i try to put it in shared memory to be read by another process i get segmentation fault after first read record..
I've read in another thread (here -> dynamic shared memory )that malloc gives sone problems with shared memory
Quote:
If you called malloc to create linked_list_header->ptr, then the address returned by malloc is private to the calling (the process that calls malloc) process. Same with NODE->buffer. You will have to allocate these things in shared "by hand" without calling malloc.
but i don't understand what i have to do now and how to solve my problem.

i tried to share object in this way:
Code:
Obj *head;     //pointer to the head of my FILLED list
int shmid;
Obj *sh;
...
shmid = shmget(SHMKEY,(sizeof(Obj)*10),0666|IPC_CREAT|IPC_EXCL);
...
sh = (Obj *)shmat(shmid, 0, 0666);
...
*sh = *head;
probably I miss something or maybe I'm totally wrong... how can I allocate Obj in shared "by hand" without calling malloc?

Thanks for your support, best regards.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:33 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0