Solved

shared object instance

Posted on 2000-04-27
4
241 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ftpcommand 2 67
Unix Question 19 50
What tool do we need to install to execute ldapsearch command in unix as well as in windows boxes. 5 154
Python Assistance 7 86
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

828 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