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

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 !!

Vincent
0
vincentlue
Asked:
vincentlue
1 Solution
 
cbarkCommented:
 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.
0
 
ianBCommented:
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
http://www.experts-exchange.com/Computers/Operating_Systems/Solaris/ 

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 cs@experts-exchange.com.
http://www.experts-exchange.com/Customer_Service/Experts_Exchange/ 

Ian
Community Support @ Experts Exchange

0
 
ANormanCommented:
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
to.

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
{
public:
 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.



0
 
vincentlueAuthor Commented:
Answer accepted
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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