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

From: David Anderson (davea_at_quasar.engr.sgi.com)
Date: 05/19/04


Date: 19 May 2004 16:15:36 GMT

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


Quantcast