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
all about shared memory vijaya2006 Linux 0 02-28-2006 04:14 AM
mmap vs shared memory - which is best for sharing data between applications? nmds UNIX for Advanced & Expert Users 2 02-21-2005 06:45 PM
Shared memory shortage but lots of unused memory cjcamaro UNIX for Advanced & Expert Users 1 10-13-2004 05:10 PM
Shared Memory Jayathirtha UNIX for Advanced & Expert Users 3 03-03-2003 12:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-23-2007
elzalem's Avatar
elzalem elzalem is offline
Registered User
  
 

Join Date: Nov 2006
Location: Lebanon
Posts: 33
Angry memory sharing - not shared memory -

hi,

this is the problem: i want to swap a linked list between 4 processes (unrelated), is there any way i can do that just by sending a pointer to a structure?
Code:
//example
typedef struct node
{
   int x;
   char c;
   struct node *next;
} node;
or i should send the items ( x,c ) by value and reconstruct the list ?
my solution: create the list in a shared location in memory, where all the processes can use the same reference to manipulate or read the list, but if i use malloc(); i can't control the physical place where the memory is allocated (that's what i know)

any help guys is appreciated, thanks
  #2 (permalink)  
Old 04-30-2007
grumpf grumpf is offline
Registered User
  
 

Join Date: May 2006
Posts: 101
hi elzalem,
there is no such think like a memory location since mem may be swaped out or what ever.
The solution depends on your requierements.
You can use a file in shared mem, the most simple solution.
of if not possible use a 'server task' that handles requests into the data structure
  #3 (permalink)  
Old 04-30-2007
elzalem's Avatar
elzalem elzalem is offline
Registered User
  
 

Join Date: Nov 2006
Location: Lebanon
Posts: 33
thanks for your reply grumpf , I've wrote a header file that contains several function to handle data structure swapping, i used message passing (message queues) but the thing is that i had to send everything by value (my data structures are complex :each node contains a queue and are filled with pointers).

I was hoping to be able to find a solution similar to the threads where all the processes share all the variables...
  #4 (permalink)  
Old 04-30-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by elzalem
I was hoping to be able to find a solution similar to the threads where all the processes share all the variables...
There is, it's called shared memory, but for some reason you discounted this option in your title.

Look at mmap(MAP_SHARED|MAP_FIXED)
  #5 (permalink)  
Old 05-01-2007
elzalem's Avatar
elzalem elzalem is offline
Registered User
  
 

Join Date: Nov 2006
Location: Lebanon
Posts: 33
i have 2 linked lists that are constantly growing or shrinking, both r visible to all processes, i don't want each process to have a copy, i hope you're understanding what i mean.
without "shared memory" is it possible?
  #6 (permalink)  
Old 05-01-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by elzalem
i have 2 linked lists that are constantly growing or shrinking, both r visible to all processes, i don't want each process to have a copy, i hope you're understanding what i mean.
without "shared memory" is it possible?
... and the moon on a stick presumably?

You can share it in memory or have another server process that contains the list and all other processes use some form of IPC or RPC to access.

You can't share something by not sharing it.

Last edited by porter; 05-01-2007 at 06:26 PM..
  #7 (permalink)  
Old 05-02-2007
elzalem's Avatar
elzalem elzalem is offline
Registered User
  
 

Join Date: Nov 2006
Location: Lebanon
Posts: 33
Quote:
Originally Posted by porter
...have another server process that contains the list and all other processes use some form of IPC or RPC to access...
in the end that's what i did! But i was trying to see if there is something i don't know about in unix that can allow me to:

p1 and p2 are 2 processes,

in p1:
int *var=malloc(sizeof(int));
send var to p2 (the address not the value)

in p2:
*var = 4; // normaly that'll give an error

I need to allow p2 to gain access to all the memory space of p1. i can simply put em in a shared memory, but i was trying to find a substitute!
Sponsored Links
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 06:53 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