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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 06-29-2009
BeNdErR BeNdErR is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 4
Thumbs up

thanks for your reply I solved my problem in another way.. but I'll try your solution too pratice makes perfect!

but there are some other question/responses I'd like to know:

1) I laughed out loud on your humor, seriously xD I'm one of those who runs away if someone divide by zero on a calculator (I hate black holes);

2) I solved my problem in this way: (7 is the number in object of my list)
Code:
Obj *pp, *head;
...
..
if((shmid = shmget(SHMKEY, 7, 0777|IPC_CREAT|IPC_EXCL)) == -1){
			perror("shmget");
			exit(1);
		}
		
		if((sh = (Obj *)shmat(shmid, 0, 0777)) ==(Obj *) -1){
			perror("shmat");
			exit(1);
		}
		int a;
		pp = head;
		for(a=0; a<7; a++){
			*(sh+a) = *pp;
			pp = pp->next;
		}
...
it seems to work fine. On the other "side" i read data this way:
Code:
Obj *p, *List;
...
p=List;
for(a=0; a<7; a++){
		*p=*(sh+a);
		p=p->next;
	}
...
what do you think about that?

3) I'm a little messed up with shared memory. I mean, what I suppose about how it works is - (hope you'll understand my english-for-dummies-language-level) - like a "box" where I can put things. But if i try to put inside a pointer I'll get maaany problems. So the list I've putted in (with my method) are no longer behaving as a list, but more likely as a """""string""""" (watch for "" ).
example:
Code:
if((shmid = shmget(SHMKEY, 7, 0777|IPC_CREAT|IPC_EXCL)) == -1){
			perror("shmget");
			exit(1);
now i've a box made of 7 slots of x-dimension. once I attach memory
(...shmat..) X becomes of a true value, in my case Obj. then I have 7 slots of Obj-size each.
when i fill my box up, i fill slots individually moving through shared memory with sh++, and not with pointer to the next obj.

is my opinion right? or completely wrong?!


thanks again