Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Use of shared memory accross processes ..

I am using shared memory in my application. The shared memory will be accessed by many processes. In the shared memory, I build simple linked lists. Assume that Process A is building this linked list and Process B
will read the linked list at a later point of time.
Consider Process A has built this :
            --------------       --------------
           |         |  .--|--->|         |  .--|-----
            --------------       --------------       |
                 Node 1              Node 2           -

My question is will Process B understand the pointer
stored in Node 1 (when it tries to traverse the linked list)? Because that pointer is virtual and
should be understood only by Process A.
1 Solution
I'd make the pointers relative to the shared memory block.
A recommended way of doing is, put all your 'pointers' in a struct at the beginning of the shared memory. Then when building the shared memory, put the offset to the  start of the shared memory inside this struct.

Then for each program working with this shared memory you have to create a local copy inside your program that will contain the real pointers. Once connected to the shared memery you know the starting address of the SM. Then fill up your local copy of the struct of pointers.

When you're only workiing  on HP-UX you can put the pointers inside the shared memory, as the shared memory will have the same starting for all connecting programs.
When working on other platforms, the SM can received different addresses depending on the size(data/code) of the connect program. So for these OS's it needed that you have a local copy of the pointers.

So the most generic way is add a header to your SM, that contains the offset to each part inside the SM, and when connecting to the SM, fill a local struct with pointers, adding the offset the start address of the SM

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now