SPUG: C question ;)

Benjamin Franks benjamin at dzhan.com
Sun Mar 10 19:35:38 CST 2002


woops!  I fat-fingered that email way too soon.  sorry for the confusion.
anyway, here should be a more complete question. ;)

I know this is a perl list, but I've had such good success with my
questions in the past, I though I'd throw out a C question.

I'd like to tie an array of structures to shared memory.  But I have
questions about accessing the elements.

So for a simple example, say I have:

typdef struct {
  time_t	a;
  time_t	b;
} my_struct;

and I create a shared memory segment with size to store 1000 of these
structs, as in:

int shmid=shmget((ftok("blah/blah",1), 1000*sizeof(my_struct), IPC_CREAT | 0666);

Then when I attach the shmid to a pointer, do I want to attach a pointer
of the my_struct type, as in:

my_struct *ptr;
ptr=shmat(shmid,NULL,0);

I guess that's where my confusion lies.  Let's say I want to work on the
500th element of my shared memory array of my_struct's.  How can I do it?

Thanks,
--Ben






 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list