The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Shared memory in shared library DreamWarrior High Level Programming 12 05-30-2007 04:33 PM
memory sharing - not shared memory - elzalem High Level Programming 9 05-02-2007 07:45 AM
help with shared memory ddx08 High Level Programming 6 04-06-2007 09:53 AM
load dynamic and shared library in kernel mtaghiloo Linux 0 08-01-2005 10:34 AM
Shared memory shortage but lots of unused memory cjcamaro UNIX for Advanced & Expert Users 1 10-13-2004 05:10 PM

Closed Thread
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
  #1 (permalink)  
Old 04-09-2006
axes axes is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 49
dynamic shared memory

Hi
I need help regarding shared memory. I need to maintain the following structure in shared memory.

struct linked_list_header{
pid_t pid;
pthread_mutex_t lock;
int top;
int end;
int free;
NODE *ptr
}
The node structure is as follows
struct NODE {
int index;
int prv;
int nxt;
void *buffer;
}
Is it possible to maintain this dynamic linked_list_header in shared memory. I tried to maintain the same BUT I am not able to share the NODE structre data among the processes.

Thanks a lot
  #2 (permalink)  
Old 04-10-2006
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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.
  #3 (permalink)  
Old 04-11-2006
axes axes is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 49
Thanks a Jim
I corrected my program to share the memory instead of malloc, Now it is working fine. I need another clarification regarding the same.

During run time, If I need more shared memory, Is it possible to mmap the increased size of dynamic memory while retaining the contents of previously mmaped memory. ( like realloc's functionality which preserves previously allocated memory contents)

Thanks once again
  #4 (permalink)  
Old 04-11-2006
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
You mmap a second memory area. However mmap is not like malloc or realloc.
It works using pages of memory, not bytes. Create a really large memory block to start with. It sounds like you're using Linux.

Linux supports system V IPC XPG4.2 calls:

sys/shm.h provides support for shmat(), shmget(), etc.. You may also want to look at those calls.
Closed Thread

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 11:31 AM.


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