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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-09-2006
Registered User
 

Join Date: Mar 2006
Posts: 45
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
Reply With Quote
Forum Sponsor
  #2  
Old 04-10-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,274
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.
Reply With Quote
  #3  
Old 04-11-2006
Registered User
 

Join Date: Mar 2006
Posts: 45
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
Reply With Quote
  #4  
Old 04-11-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,274
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0