[TriLUG] anybody use pointers and shared memory?

H Brett Bolen wingedlizard at nc.rr.com
Wed May 15 16:44:53 EDT 2002


John F Davis wrote:
> Hello
> 
> I know how to use shared memory between processes via shmget and shmat, but
> I'm not an expert on their use.  (I've used it for simple flat structures.)
> Anybody have any experience using them with something similar to malloc'd
> pointers?  For instance, if I want to dynamically allocate data that is
> shared, do I have to use shmget/shmat in lieu of malloc?
> 

Hey John,

There is a very simple wrapper class, SharedArray,  here:

  http://www.pressenter.com/~3nelsons/joecode/

it's implemented in the header file, and is easy to use.  as long as
the destructors are called, everything is cleaned up.

use is as simple as

   typedef struct {
     ...
   } MyStruct;

   MyStruct *MyStructArray = new SharedArray< MyStruct> ( "Name", 100);

   MyStructArray[1] = ...

   delete MyStructArray;

may not be exact, but close.


b\375

ps:  I'm forwarding this to dev at trilug.org




More information about the TriLUG mailing list