Re: How To Make Shared Memory (mmap woun't do it!) Aliased To Pre-Existing C Struct Memory?

From: Ash (amujoo_at_yahoo.com)
Date: 05/20/04


Date: 19 May 2004 22:19:25 -0700

you could simply define a shared memory segment of the same size as
the existing C struct. then attach the shared memory structure in your
program and use it just like any other structure.

davea@quasar.engr.sgi.com (David Anderson) wrote in message news:<c8g178$oaiaj$1@fido.engr.sgi.com>...
> In article <d5cfdc47.0405190755.59b4da4@posting.google.com>,
> Christopher M. Lusardi <clusardi2k@aol.com> wrote:
> >Hello,
> >
> > My problem is I am in the process of changing the implimentation of
> >my shared memory.
> >
> > What I want to do is use something such as mmap to access shared
> >memory and to overlay my struct memory onto shared memory. Is it even
> >possible? Do you have a simple coding example that will do this?
> >
> >So, I basically have in old code :
> >
> >struct
> >{
> > int status [300];
> > float black_box [300];
> > char message [300 * 4];
> >} shared_memory;
> >
> > I then use shared_memory.status [0] to access the first element
> >etc.
> >
> > How can I use the dotted identifier "shared_memory" and have it
> >refer to shared memory out there some where?
> >
> >Thank you,
> >Christopher Lusardi
>
> struct mysm {
> int status [300];
> float black_box [300];
> char message [300 * 4];
> };
>
> ... mmap something
> struct mysm *shared_memory = mmap area.
> Then
> shared_memory->status
> will work and is a portable notion.
>
> <OFF TOPIC>
> I would suggest a bit more care in naming things. The compiler
> does not care but some person may... grep is only useful if
> you don't have too many accidental matches in names you grep for.
> </OFF TOPIC>
>
>
> David Anderson



Relevant Pages