473,795 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Shared objects and virtual functions

Hi,
Hopefully this is thecorrect group, its a bit C++ and a bit POSIX...

Ive had a look in the archives, and Im a bit confused....

I have some classes in a shared library (a .so on a QNX system) which I
want to instantiate into shared memory so that 2 processes can both
operate on the same data. The classes have a quite derived ineritance
tree (not sure if this is the correct term) where I have several
classes derived from a base class. The problem I think ill have is that
the base class has virtual functions istypeA() istypeB() etc all return
false in the base class and return true in the derived classes which
only implement the appropriate one. This allows easy determination of
type from a base class ptr. There are also other virtual functions but
its late and I cant remember what for. Some classes have ptrs to other
ones, which I think I can fix either by having 2 ptrs one for each
process, or by using physical addresses in the ptrs.
I understand that the vtable (this only contains virtual funcs right?)
will be process memory map specific, and if the objects dont get mmaped
into the same location then the second ones will not work, probably in
'interesting ways' I come from a c / asm background, where this sort
of dynamic problem doenst occur (well, i havent come accross it)
Can anyone sugest a way around this? I cannot guarentee the virtual
addresses will be the same, though its likely. is it possible to
'fiddle' with the vtable in an elegant way?
Or a way to get rid of the virtual funcs but still allow the baseptr
determination (implement each function in all the derived classes?)
I could (from memory) create a set of data only classes and some
accessor classes, but this is a port of a legacy system, so Id like to
avoid changing it *to* much if possible. (and Im not entirely sure how
to do this either...)

The design is not yet set, so suggestions / comments appreciated.

thanks

Dave

Sep 7 '06 #1
2 2452
da************* @bem.fki-et.com wrote:
Hi,
Hopefully this is thecorrect group, its a bit C++ and a bit POSIX...
It's mostly off-topic here, but see below for a C++ solution.
Ive had a look in the archives, and Im a bit confused....

I have some classes in a shared library (a .so on a QNX system) which I
want to instantiate into shared memory so that 2 processes can both
operate on the same data. The classes have a quite derived ineritance
tree (not sure if this is the correct term) where I have several
classes derived from a base class. The problem I think ill have is that
the base class has virtual functions istypeA() istypeB() etc all return
false in the base class and return true in the derived classes which
only implement the appropriate one. This allows easy determination of
type from a base class ptr. There are also other virtual functions but
its late and I cant remember what for. Some classes have ptrs to other
ones, which I think I can fix either by having 2 ptrs one for each
process, or by using physical addresses in the ptrs.
I understand that the vtable (this only contains virtual funcs right?)
will be process memory map specific, and if the objects dont get mmaped
into the same location then the second ones will not work, probably in
'interesting ways' I come from a c / asm background, where this sort
of dynamic problem doenst occur (well, i havent come accross it)
Can anyone sugest a way around this? I cannot guarentee the virtual
addresses will be the same, though its likely. is it possible to
'fiddle' with the vtable in an elegant way?
Or a way to get rid of the virtual funcs but still allow the baseptr
determination (implement each function in all the derived classes?)
I could (from memory) create a set of data only classes and some
accessor classes, but this is a port of a legacy system, so Id like to
avoid changing it *to* much if possible. (and Im not entirely sure how
to do this either...)
You don't need any ugly hacks. The C++ language has a typeid operator
to determine types dynamically. You may need to use a compiler switch
to enable RTTI. Check the compiler manual.

Regards,
Bart.

Sep 7 '06 #2

Bart wrote:
da************* @bem.fki-et.com wrote:
Hi,
Hopefully this is thecorrect group, its a bit C++ and a bit POSIX...

It's mostly off-topic here, but see below for a C++ solution.
Ive had a look in the archives, and Im a bit confused....

I have some classes in a shared library (a .so on a QNX system) which I
want to instantiate into shared memory so that 2 processes can both
operate on the same data. The classes have a quite derived ineritance
tree (not sure if this is the correct term) where I have several
classes derived from a base class. The problem I think ill have is that
the base class has virtual functions istypeA() istypeB() etc all return
false in the base class and return true in the derived classes which
only implement the appropriate one. This allows easy determination of
type from a base class ptr. There are also other virtual functions but
its late and I cant remember what for. Some classes have ptrs to other
ones, which I think I can fix either by having 2 ptrs one for each
process, or by using physical addresses in the ptrs.
I understand that the vtable (this only contains virtual funcs right?)
will be process memory map specific, and if the objects dont get mmaped
into the same location then the second ones will not work, probably in
'interesting ways' I come from a c / asm background, where this sort
of dynamic problem doenst occur (well, i havent come accross it)
Can anyone sugest a way around this? I cannot guarentee the virtual
addresses will be the same, though its likely. is it possible to
'fiddle' with the vtable in an elegant way?
Or a way to get rid of the virtual funcs but still allow the baseptr
determination (implement each function in all the derived classes?)
I could (from memory) create a set of data only classes and some
accessor classes, but this is a port of a legacy system, so Id like to
avoid changing it *to* much if possible. (and Im not entirely sure how
to do this either...)

You don't need any ugly hacks. The C++ language has a typeid operator
to determine types dynamically. You may need to use a compiler switch
to enable RTTI. Check the compiler manual.

Regards,
Bart.
Thanks, I didnt know about that, and its used in other places already
(I wonder how much attention the original coder was paying from day to
day...)
I think I can work around most of the virtuals using this. I have to do
some ugly 'not inherited - call the correct derived one' code to remove
the rest, but the legacy system part of this hasnt changed in years, so
the loss of OO approach is probably no problem for this small subset
and the amount of other work it would save.

Dave

Sep 8 '06 #3

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

Similar topics

4
4212
by: listigerBiber | last post by:
Hello, i want to extend a program of mine with a plugin architecture. I can load and use the shared libs which are implementations of a abstract base class without any problems. But what i need is a bi-directional interface, the plugins have to acess objects of the main programm (pointers to them are passed at plugin initialisation). This works too - but only if i include the header and .cpp files of these api objects into every plugin...
1
1650
by: Gregg Altschul | last post by:
I have a Shared Object which its sole purpose is to create objects of a certain type and return a pointer to the object to the user. Therefore, the user becomes the owner of this object and is resposible for deleting it. It utilizes the factory pattern to create the objects. The problem is that I am finding it nearly impossible to get rid of my Text Relocations. I'm using the -Kpic and -ztext options (which, of course, makes my link-edit...
1
1642
by: Alfonso Morra | last post by:
Anyone knows why it is not possible (at least without a great deal of "jiggery-pockery" behind the scenes), to store objects that contain virtual functions in a shared memory block? I think I know the answer - possibly something to do with unresolvable function addresses when mapping from vf table to virtual address - but this is an uneducated guess at best, on my part. It would be useful to get a more experienced C++ programmers' view...
5
7821
by: Bernard | last post by:
Hi, Is there a way to have the virtual table of c++ objects allocated in shared memory (in fact in the same address space as the object is) instead of having it allocated in the process address space ? This could be useful to share objects between processes without having to call the constructor of the object twice (I think it is the constructor that is creating the virtual table, right ?) Thanks
11
3364
by: tshad | last post by:
I am setting up some of my functions in a class called MyFunctions. I am not clear as to the best time to set a function as Shared and when not to. For example, I have the following bit manipulation routines in my Class: ******************************************************************************* imports System NameSpace MyFunctions
15
4946
by: Rob Nicholson | last post by:
A consequence of the ASP.NET architecture on IIS has just hit home with a big thud. It's to do with shared variables. Consider a module like this: Public Module Functions Public GlobalName As String ' this is ineffect a global application object End Module
31
3206
by: JoeC | last post by:
I have read books and have ideas on how to create objects. I often create my own projects and programs. They end up getting pretty complex and long. I often use objects in my programs they are some of the most powerful programming tools I have found. Often times as my program grows so do my objects. Often times I look back and see that my objects could be broken down int several smaller more re-usable module pieces of code. Is it a...
4
3635
by: KishorAditya | last post by:
Hi All, Consider the following scenario: class Top { }; class Left: virtual public Top { }; class Right: virtual public Top { }; class Bottom: public Left, public Right {}; Many books propose that object of Bottom contains three vptrs, one for Left and Bottom, one for Right and one for Top. Now my question is why the compiler is storing superclasses' vptrs in
21
8391
by: llothar | last post by:
Hello, i need to manage a heap in shared memory. Does anybody know about a portable (win32+mac+posix) c implementation for this.
0
9519
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
10438
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...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
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
9042
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...
0
6780
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
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
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.