473,385 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 7799
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_memory_address) O(my_init);

process B use object O
O* o = new(o) O(no_init_of_attribute); // 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.*******@genesys.com> wrote in message
news:<42***********************@read.news.fr.uu.ne t>...
Well I think I can:

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

process B use object O
O* o = new(o) O(no_init_of_attribute); // Constructor of O called,
virtual-table is created again
How about casting the shared_memory_address 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_cast, 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....virtual 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
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...
4
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...
1
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...
17
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...
2
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...
4
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
by: Shraddha | last post by:
What is the use of "PURE vitual distructors"? And why we can not have vitual constructors?
4
by: Anarki | last post by:
##include <iostream> using namespace std; class A { }; class B:virtual public A { }; class C:virtual public A
0
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.