473,804 Members | 3,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

virtual table and shared memory

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

Aug 3 '05 #1
5 7821
Ian
Bernard wrote:
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 ?

Sorry, no.

Ian
Aug 3 '05 #2
Ian
Bernard wrote:

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 ?)

Forgot to say, you just plain can't share objects with virtual methods
via shared memory.

Ian
Aug 3 '05 #3
Well I think I can:

process A create object O:
O* o = new(shared_memo ry_address) O(my_init);

process B use object O
O* o = new(o) O(no_init_of_at tribute); // Constructor of O called,
virtual-table is created again

This seems to work with g++. Wondering if I could avoid the 2nd call of the
constructor

"Ian" <no***@nowhere. com> wrote in message
news:11******** *******@drone2-svc-skyt.qsi.net.nz ...
Bernard wrote:

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 ?)

Forgot to say, you just plain can't share objects with virtual methods via
shared memory.

Ian

Aug 3 '05 #4

Bernard schreef:
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 ?


vtables are just one way to implement virtual functions, and ISO C++
doesn't
even have shared memory, or address spaces. Your question therefore is
off-topic here, ask in your OS/compiler group.

(In general, you wouldn't want it either. If you've got two copies of a
function in two different address spaces, on different addresses, you'd
also want two tables of function pointers. Plus, you'd want two vtable
pointers in each object, and some way of knowing which one to use. E.g.
it really doesn't work nicely. Plus there's RTTI which often is done
via the vtable, too)

Aug 3 '05 #5
"Bernard" <b.*******@gene sys.com> wrote in message
news:<42******* *************** *@read.news.fr. uu.net>...
Well I think I can:

process A create object O:
O* o = new(shared_memo ry_address) O(my_init);

process B use object O
O* o = new(o) O(no_init_of_at tribute); // Constructor of O called,
virtual-table is created again
How about casting the shared_memory_a ddress in process B to O*? wouldn't
that work?
alsom its not just the ctor, u dont want a call to dtor in process B
using type cast or reinterpret_cas t, is more safe?
This seems to work with g++. Wondering if I could avoid the 2nd call of
the constructor

I think there is no virtual table per object....virtu al table is a class
variable.
all the obejcts of the same class shares/uses the same vtable?
Aug 6 '05 #6

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

Similar topics

5
1727
by: News Admin | last post by:
I have a bunch of classes, instances of which that need to live in shared memory and be accessed by multiple processes. This means that they cannot have a vtable as the addresses in it will be in the address space of the process that originally created the shared memory and therefore unavailable to the other processes that may wish to use these instances of the classes. Every so often I forget this and introduce a virtual function causing...
4
2903
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that there shouldn't have been a "virtual" keyword for this purpose, but instead, a "nonvirtual" keyword! In teaching inheritance, you see the common example: class Vehicle {}
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...
17
12840
by: Dr NoName | last post by:
Help! I have a table that multiple processes must be able to write to concurrently. However, it for some reason gets locked in exclusive mode. I narrowed it down to one SQL statement + some weirdness with foreign keys. To debug this, I opened two psql sessions and typed in the sql statements manually. Here is the situation: CREATE TABLE take2
2
2453
by: david.sanderson | last post by:
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...
4
2152
by: cwc5w | last post by:
I have two classes. One with a regular destructor and the other with a virtual destructor. e.g. class x { ~x(){} } vs
8
2337
by: Shraddha | last post by:
What is the use of "PURE vitual distructors"? And why we can not have vitual constructors?
4
2058
by: Anarki | last post by:
##include <iostream> using namespace std; class A { }; class B:virtual public A { }; class C:virtual public A
0
1638
by: George2 | last post by:
Hello everyone, Sorry that this question is related to another question I posted some time before because I have some new findings and self-analysis. My question is why sometimes from perfmon on Windows, working set larger than virtual memory? I think virtual memory is the total size of memory (committed, reserved, shared, private) and working set is just the RAM touched by current process currently. Virtual memory should always larger...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9584
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
10583
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
10337
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...
0
9160
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
7622
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
5525
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...
0
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.