473,597 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible to put a class object in share memory?

Greeting,

My platform is Solaris 2.8. My question is that if there is a simple way to
put a class object in share memory, so that multiple process can use this
object.

Thanks in advance!
Evan
Jul 22 '05 #1
3 2090

"music4" <mu****@163.net > wrote in message news:cg******** @netnews.proxy. lucent.com...
Greeting,

My platform is Solaris 2.8. My question is that if there is a simple way to
put a class object in share memory, so that multiple process can use this
object.


Look up functions called shm* in the Solaris docs.

However, it's actually NOT easy for any but the most trivial classes
to share memories as there are pointers both explicit and hidden inside
class objects that may not be valid in different processes.

Jul 22 '05 #2
"music4" <mu****@163.net > wrote in message news:<cg******* *@netnews.proxy .lucent.com>...
Greeting,

My platform is Solaris 2.8. My question is that if there is a simple way to
put a class object in share memory, so that multiple process can use this
object.


The usual way is to allocate the shared memory, then use the placement
new operator to construct an object there. If you have a type of
object that is always shared, you can instead overload its operator
new to allocate shared memory.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 22 '05 #3
"music4" <mu****@163.net > wrote in message news:<cg******* *@netnews.proxy .lucent.com>...
Greeting,

My platform is Solaris 2.8. My question is that if there is a simple way to
put a class object in share memory, so that multiple process can use this
object.

Thanks in advance!
Evan


The direct way is to allocate[1] a chunk of that shared memory for
your object, and then use placement new[2] to initialise the instance
in that memory.

The user-friendly-but-more-work way[3] is to write an operator new for
the class which takes as an extra argument the shared memory
'arena'[4] you want the object created in.
Footnotes:
[1] - you need some allocator for your shared memory which provides
the equivalent of new and delete functions for allocating/releasing
chunks of that shared segment. This might be entirely trivial if you
only ever want an array of one type of object, but it could be a
full-fledged heap implementation.

[2] - see the C++ FAQ or your favourite reference if you haven't used
this - it initialises an object in some raw memory.

[3] - this is only really friendlier if you're allocating these things
all over the place, and don't want to change the client code (much).
If you're using a factory function, there isn't much point doing this.

[4] - this could just be a pointer to the start of your shared memory
segment if your allocation routine is simple and well-known, or it
could be a pointer to an allocator object (see [1] again) which
provides a known allocation interface, where some allocator instance
is associated with a particular shm segment. See the C++ FAQ (again) -
section 11.14.
Caveats:
Note that if your objects aren't POD, you'll have to make sure that
all their subobjects allocate from the same shared memory segment.
For things like std::string, that means the typedef breaks, since you
need to pass std::basic_stri ng a different allocator.

Also, none of this will work for objects having virtual functions,
because the vtable pointer will hold an address specific to the
process which created the object.
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1846
by: Lars Plessmann | last post by:
Hello! I try to use PHP session function, and it doesn't work properly. :-( I want to pass a whole object from site A to site B to minimize Database connections. I don't use GLOBALS = ON. My param GLOBALS is set to OFF and has be be keept off! Well. I want to pass a complete object of class article from website A
13
2361
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes. Two sub-classes have the relationship to communicate back and forth through this pointer. The pointer is responsible inside Top class for allocating and deallocating two sub-classes. CMemory class is responsible to allocate and deallocate memory...
11
2226
by: dimension | last post by:
If my intentions are to create objects that encapsulates data rows in a table, is it better to use a Struct or Class? Based on what i read, if my objects will simply have get and set methods, Struct is may be better...but i am looking for some advise from the experts on this? Assumptions: it is possible for some operations, i may have 8000 to 10000 (or more) objects instantiated. what are some considerations in designing a system that...
7
4874
by: isamusetu | last post by:
anybody knows how to share the dll between the process? I know there is a way to set the #pragma data_seg in the visual studio 6.0 C++, that can make the dll can be shared between the multiple processes. but how to do it in .net? -- ISAMUSETU
2
1464
by: Chakravarthy | last post by:
Given an XML stream as below, is there any possibility to convert the same into any treditional class style with . (dots) as seperator of the nodes of the xml file... for instance bank.code.tostring() should reslut me "5070" and bank.description.tostring() should result "ICICI - Bangalore"
9
1788
by: Amit Bhatia | last post by:
User-Agent: OSXnews 2.081 Xref: number1.nntp.dca.giganews.com comp.lang.c++:817840 hi, I was wondering how to do the following. I have a class A, class A{ //; int a;
2
1697
by: Chicken15 | last post by:
Hi Group. First of all I'm sorry for asking (maybe) such easy questions. But I'm quite stuck now and couldn't come up with a solution by using my C# book or googling. So it would be nice if someone could help me out. Now first of all I want to describe the setting in a simpler (I'm using Visual Studio 2005): Form: One comboBox (dropdown list) and 2 buttons. Classes: Class1 with a function do() which plainly returns a string.
10
1513
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
In my application, I make use of the Borg idiom, invented by Alex Martelli. class Borg(object): '''Borg Idiom, from the Python Cookbook, 2nd Edition, p:273 Derive a class form this; all instances of that class will share the same state, provided that they don't override __new__; otherwise, remember to use Borg.__new__ within the overriden class.
1
1307
by: shapper | last post by:
Hello, I am defining a class as follows: stat = new Stat { Count = Roles.GetUsersInRole(RoleType.Administrator.ToString ()).Count(), Share = Count / UserCount * 100, UserCount = Membership.GetAllUsers().Count };
0
7886
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8035
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5431
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1238
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.