Solved

shared object instance

Posted on 2000-04-27
4
244 Views
Last Modified: 2013-12-27

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
Comment
Question by:vincentlue
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Expert Comment

by:cbark
ID: 2789986
 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
 
LVL 5

Expert Comment

by:ianB
ID: 2855585
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
 

Accepted Solution

by:
ANorman earned 100 total points
ID: 2945915
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
 

Author Comment

by:vincentlue
ID: 3051810
Answer accepted
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question