shared object instance

I want to have an c++ class instance
shared by serveral processes during
run-time. Is it possible in Solaris ?

Is there a mechanism where an instance
can be instantiated in a single dynamically linked library shared by
different processes ??

Thanks !!

Who is Participating?
ANormanConnect With a Mentor Commented:
The way that I have used before is to create
a chunk of shared memory using a key that
all the connecting processes can get access

Then the object can be created in shared
memory by overriding the new() operator.

There are a few things to keep in mind:
You cannot use any virtual functions that
are allocated by another process. To get these
working means playing around with a new()
function that takes a pointer to a already allocated
object. This then causes problems with the
constructor initialising attributes.

Also remember that the accessing of the methods
are async and you need to provide some form
of locking to ensure that race conditions and
problems such as these cannot occur.

So the process will have to have something like.

int main()
 key_t key = getKey();
 void *memBlock = createMemoryBlock(key);
 SharedClass *obj = new(memBlock) SharedClass().

class SharedClass
 void *operator new(void *mem) { return mem; }

NOTE: I cannot remember the various parameters
to the shared memory functions used to create
the memory ... but the function is shmget.

 This is something that would be fun to do (and that I've wanted to play with).  You could possibly try and override the new() function to allocate shared memory (or set your object up to keep attributes in shared memory).
  It would be a lot easier to use CORBA to share your objects between processes.
We have opened up a new Solaris Topic Area.  

To increase the visibility of questions, we moved questions we felt
appropriate to the new Solaris Topic Area where they will be easier for
Solaris experts to find and answer. You may view your question at 

If you have any questions about the new topic area you can contact
Community Support by posting a comment at the following URL or by
emailing us at 

Community Support @ Experts Exchange

vincentlueAuthor Commented:
Answer accepted
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.