Solved

shared object instance

Posted on 2000-04-27
4
231 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
Comment Utility
 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
Comment Utility
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
Comment Utility
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
Comment Utility
Answer accepted
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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 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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now