473,769 Members | 3,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Virtual destructors and vtable layout

James Kanze <ja*********@gm ail.comwrote:
The vtable layout used by the C++ compiler has nothing to do
with what the component model does. None of the component
models I'm familiar with even use a vtable, except insofar as
they map to C++ code, in which case, they're just normal C++
code.
COM does rely on vtable layout. COM interfaces are declared
as pure virtual classes, all methods using stdcall convention, and
this works because most (if not all) C++ compilers for the MSW
use a very similar vtable layout.
How could they, when you think about it? The usual vtable
implementation contains pointers into the local process; by
definition, a component model allows calling between processes,
and generally between machines with different architectures.
(Otherwise, why bother with it.)
In COM, this is handled by proxies provided by system dlls,
and they rely on that same vtable layout.
If you're designing a plugin interface, it's up to you to decide
how to define it, but usually, at least under Windows and Unix,
it's defined in terms of C, to leverage off the system-wide C
language API.
Strictly speaking, COM and UNO interfaces are defined in
terms of an IDL but it's common practise to use C++ classes
(I don't think I've ever seen this stuff coded as explicit vtables
in C.)
Oct 11 '08 #1
10 3652

James Kanze <ja*********@gm ail.comwrote:
On Oct 11, 4:21 am, "Ole Nielsby"
<ole.niel...@te kare-you-spamminglogisk. dkwrote:
James Kanze <james.ka...@gm ail.comwrote:
The vtable layout used by the C++ compiler has nothing to do
with what the component model does. None of the component
models I'm familiar with even use a vtable, except insofar
as they map to C++ code, in which case, they're just normal
C++ code.
COM does rely on vtable layout. COM interfaces are declared
as pure virtual classes, all methods using stdcall convention, and
this works because most (if not all) C++ compilers for the MSW
use a very similar vtable layout.

In other words, COM is pretty much unusable.
COM is a mess - but very usable.
Seriously, you've got to be kidding. How does it work when the
components are on different machines? Running different
binaries with the functions at different addresses?
By client proxies that communicate with the server components
using the network. The system libraries supply proxies for common
interfaces.
Either it's not really a component model, but just a means of
supporting linking different languages (which, admittedly, all
systems should provide), or you've misunderstood something.
I think COM does qualify as a component model, though
not a particularly consistent one. I know for sure that the
C++ headers used by C++ COM programs do rely on
the compiler using a specific layout for the vtables. This
may be undefined according to the C++ standard but it's
very widely used.
Oct 12 '08 #2
On Oct 12, 2:44*am, "Ole Nielsby"
<ole.niel...@te kare-you-spamminglogisk. dkwrote:
James Kanze <james.ka...@gm ail.comwrote:
On Oct 11, 4:21 am, "Ole Nielsby"
<ole.niel...@te kare-you-spamminglogisk. dkwrote:
James Kanze <james.ka...@gm ail.comwrote:
The vtable layout used by the C++ compiler has nothing
to do with what the component model does. None of the
component models I'm familiar with even use a vtable,
except insofar as they map to C++ code, in which case,
they're just normal C++ code.
COM does rely on vtable layout. COM interfaces are
declared as pure virtual classes, all methods using
stdcall convention, and this works because most (if not
all) C++ compilers for the MSW use a very similar vtable
layout.
In other words, COM is pretty much unusable.
COM is a mess - but very usable.
Only in very limited contexts. And it probably should be
avoided even then, because its limitations prevent future
growth. If you can't easily move a component from one machine
to another, there's really no point in using a component
architecture, is there?
Seriously, you've got to be kidding. *How does it work when the
components are on different machines? *Running different
binaries with the functions at different addresses?
By client proxies that communicate with the server components
using the network. The system libraries supply proxies for
common interfaces.
In that case, who cares how the vtable is laid out. The proxy
is compiled in whichever language you want, and has the correct
vtable for that language and that compiler.

That's really how Corba works. (At that particular
level---there's a lot more to Corba. Which is nice if you
need it, and a major overhead if you don't.)
Either it's not really a component model, but just a means
of supporting linking different languages (which,
admittedly, all systems should provide), or you've
misunderstood something.
I think COM does qualify as a component model, though not a
particularly consistent one. I know for sure that the C++
headers used by C++ COM programs do rely on the compiler using
a specific layout for the vtables. This may be undefined
according to the C++ standard but it's very widely used.
But if the COM interface definition is in C++, you can compile
it to another language, using that language's binding. And if
you're using proxies, the vtable layout doesn't matter. And
can't; it makes no sense to say that the vtable layout is the
same on a Sparc as it is on a PC.

But if I understand you correctly, COM mixes two very different
concepts: a component model (using proxies, etc.), and a
specification for a mixed language platform specific API. The
latter needs a lot more than just a consistent vtable layout, of
course, but presumable, Microsoft ensures that all the rest
works as well in the tool chains it provides. (The problem is
that except for C++, and maybe C#, it doesn't provide any other
useful language. In mixed language programming, the "other"
language is usually either a legacy language---Cobol or
Fortran---or a language targetting a different model, like Perl,
Python, Ruby or Java.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 12 '08 #3
James Kanze <ja*********@gm ail.comwrote:
[...]
But if I understand you correctly, COM mixes two very
different concepts: a component model (using proxies, etc.),
and a specification for a mixed language platform specific API.
I think that's correct.
The latter needs a lot more than just a consistent vtable layout,
of course, but presumable, Microsoft ensures that all the rest
works as well in the tool chains it provides.
It works with non-MS compilers, too. COM components can
be compiled by VC, Borland, GCC... and still work together
by virtue of compatible vtables.

XPCOM (the Mozilla/Firefox component model) and UNO
(the component model of OpenOffice) work much the same
way.

I think this style of interfacing was chosen because of its low
overhead when used in-process - all it takes to cross a
component border is a virtual call. So it fits with the
pay-per-use philosophy: you pay for the marshalling
only if you need it.

IMO it would be nice if C++ had some way of enforcing
a standard vtable layout.so that component models like
this could be used without relying on what is strictly
speaking undefined beaviour.
Oct 12 '08 #4
Ole Nielsby wrote:
James Kanze <ja*********@gm ail.comwrote:
>[...]
But if I understand you correctly, COM mixes two very
different concepts: a component model (using proxies, etc.),
and a specification for a mixed language platform specific API.

I think that's correct.
> The latter needs a lot more than just a consistent vtable layout,
of course, but presumable, Microsoft ensures that all the rest
works as well in the tool chains it provides.

It works with non-MS compilers, too. COM components can
be compiled by VC, Borland, GCC... and still work together
by virtue of compatible vtables.

XPCOM (the Mozilla/Firefox component model) and UNO
(the component model of OpenOffice) work much the same
way.

I think this style of interfacing was chosen because of its low
overhead when used in-process - all it takes to cross a
component border is a virtual call. So it fits with the
pay-per-use philosophy: you pay for the marshalling
only if you need it.

IMO it would be nice if C++ had some way of enforcing
a standard vtable layout.so that component models like
this could be used without relying on what is strictly
speaking undefined beaviour.
If becomes implementation specific behaviour, when the compilers
support it. As far as I know, this is only done for x86 hardware.

The problem with defining implementation details is that is goes WAY
down to the underlying hardware. One example of what not to do is Java
specifying IEEE floating point, even for hardware that doesn't have
it. This has forced IBM to add another set of FP hardware to its
mainframes. Very expensive!

Would you like them to support Windows COM compatible vtables on z/OS
as well?
Bo Persson
Oct 12 '08 #5
On 2008-10-12 16:46, Ole Nielsby wrote:
James Kanze <ja*********@gm ail.comwrote:
>[...]
But if I understand you correctly, COM mixes two very
different concepts: a component model (using proxies, etc.),
and a specification for a mixed language platform specific API.

I think that's correct.
> The latter needs a lot more than just a consistent vtable layout,
of course, but presumable, Microsoft ensures that all the rest
works as well in the tool chains it provides.

It works with non-MS compilers, too. COM components can
be compiled by VC, Borland, GCC... and still work together
by virtue of compatible vtables.
IMO it would be nice if C++ had some way of enforcing
a standard vtable layout.so that component models like
this could be used without relying on what is strictly
speaking undefined beaviour.
Strictly speaking it is not undefined behaviour, it is just not defined
in the C++ standard. Which is OK, most development probably relies on
stuff not specified in C or C++ (POSIX comes to mind).

Actually I prefer it that way, the language standard should try not to
specify implementation-details unless necessary, and leave it up to each
platform to provide such details and more (such as how to interop with
other languages/components/applications/etc.).

--
Erik Wikström
Oct 12 '08 #6
On Oct 12, 4:46*pm, "Ole Nielsby"
<ole.niel...@te kare-you-spamminglogisk. dkwrote:
James Kanze <james.ka...@gm ail.comwrote:
[...]
The latter needs a lot more than just a consistent vtable
layout, of course, but presumable, Microsoft ensures that
all the rest works as well in the tool chains it provides.
It works with non-MS compilers, too. COM components can be
compiled by VC, Borland, GCC... and still work together by
virtue of compatible vtables.
XPCOM (the Mozilla/Firefox component model) and UNO (the
component model of OpenOffice) work much the same way.
Do they? Firefox requires that its plugins be compiled with a
specific compiler?
I think this style of interfacing was chosen because of its
low overhead when used in-process - all it takes to cross a
component border is a virtual call.
But that's the case with the Corba implementations I've used as
well. When the language binding supports it.
So it fits with the pay-per-use philosophy: you pay for the
marshalling only if you need it.
IMO it would be nice if C++ had some way of enforcing a
standard vtable layout.so that component models like this
could be used without relying on what is strictly speaking
undefined beaviour.
IIUC, what you're requesting is that the C++ standard impose
implementation details on other languages. I don't think it's
possible.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 12 '08 #7
>James Kanze wrote:
>But that's the case with the Corba implementations I've used as
well. When the language binding supports it.
May I ask which ORB you're referring to an how it is implemented?
Specifically, I'd like to know:
1. Do you need a different declaration in IDL, something like "local"
2. May you use the same interface both as local (without marshalling)
and remote?
3. Do you get 2 different sets of skeleton and proxies for local and
remote?

Thanks in advance,
Yakov
Oct 13 '08 #8
On Oct 13, 1:52 pm, Yakov Gerlovin <yakov.gerlo... @gmail.comwrote :
James Kanze wrote:
But that's the case with the Corba implementations I've used as
well. When the language binding supports it.
May I ask which ORB you're referring to an how it is implemented?
I've used several. I've not really looked into the
implementation, but I do know that it doesn't marshal if the
object is located in the same process.
Specifically, I'd like to know:
1. Do you need a different declaration in IDL, something like "local"
No.
2. May you use the same interface both as local (without marshalling)
and remote?
Yes. At least I think so (it's been some time ago); the
decision is runtime; depending on where the object is located,
you'll end up with the marshalling proxy, or the actual object.
3. Do you get 2 different sets of skeleton and proxies for local and
remote?
No. IIRC, you don't even have a proxy for local objects.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 13 '08 #9
James Kanze <ja*********@gm ail.comwrote:

On Oct 12, 4:46 pm, "Ole Nielsby"
<ole.niel...@te kare-you-spamminglogisk. dkwrote:
James Kanze <james.ka...@gm ail.comwrote:
[...]
The latter needs a lot more than just a consistent vtable
layout, of course, but presumable, Microsoft ensures that
all the rest works as well in the tool chains it provides.
It works with non-MS compilers, too. COM components can be
compiled by VC, Borland, GCC... and still work together by
virtue of compatible vtables.
XPCOM (the Mozilla/Firefox component model) and UNO (the
component model of OpenOffice) work much the same way.
Do they? Firefox requires that its plugins be compiled with a
specific compiler?
I'm not deep into XPCOM but UNO/OpenOffice is compiler
dependent, and the MSW build is tied to VC6 which is sort
of tragic for an application that's supposed to challenge the
Microsoft monopoly in office software, and a major deterrent
from using UNO IMO.

This dependency isn't caused by vtable issues. It has to do with
components' use of rtl, and an issue with COM interop that
depends on ATL.
Oct 13 '08 #10

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

Similar topics

4
4427
by: vijay | last post by:
I have a doubt with size of classed with virtual functions I have declared A,A1,A2 ,B , C, D some classes with no varaibles but a vitual function each, The size of A is as expected 4 bytes with one vtbl ptr BUt when I derive the class B from class A (both have 1 virtual function each ) the size remains still as 4 bytes . class A = 4 bytes class B :public A = 4 bytes class...
23
4494
by: Giancarlo Niccolai | last post by:
Hello all. I have peeked through the FAQ and all relevant links, and also through Stroustrup book, but I have not been able to find an answer, so I have to post here as a last resort. It makes sense that if you have virtual destructors, they are eventually used in the explicit destructor call when using the placement new semantic: class A {
15
2121
by: christopher diggins | last post by:
I posted to my blog a special pointer class work-around for inheriting from base classes without virtual destructors. I was wondering if there is any other similar work, and whether there are any problems with my proposed approach. Thanks in advance! See http://www.artima.com/weblogs/viewpost.jsp?thread=107587 For those who just want the code: template<typename target_type> class base_class_ptr {
23
2157
by: heted7 | last post by:
Hi, Most of the books on C++ say something like this: "A virtual destructor should be defined if the class contains at least one virtual member function." My question is: why is it only for the case when the class contains at least one virtual member function? Shouldn't the destructor always be virtual, whenever there's a possibility that an inherited object will be destructed through a base class pointer? (This does not require,
7
2208
by: Oleksii | last post by:
Hello, I'm rather new to the advanced topics, therefore I cannot explain the following myself. Could anyone give me a hint on this one? I'm trying to avoid link-time dependencies on (a test version of) certain classes. In other words I don't want to link stuff that I don't use. One thing that worked for me was replacing instance members (MyClass myClass) within a class with auto_ptr (auto_ptr<MyClass> myClass) and initializing it with...
2
1793
by: Vladimir_petter | last post by:
Hello All, I've fount that if I compile the same program using gcc and vc 2003 the same class E (see complete source bellow) has different size (on vc it is 4 bytes bigger). Digging into this I've found that vc is reserving a dword in the E class right before storage for virtual base class. In my tests value of this dword always was 0. I did not see any code referencing this memory. Anybody has any idea what this dword is for? ...
9
2429
by: ypjofficial | last post by:
Hello All, I am defining a class with one virtual function and storing its first 4 bytes ie. the address of the virtual function table to a file.I am again rereading the file in the same program and calling the virtual function.The function gets called nicely but it shows the junk values for the member variables of the class of which the function is a member..below is the code //Program start #include "iostream.h"
5
11360
by: druberego | last post by:
I read google and tried to find the solution myself. YES I do know that you can get undefined references if you: a) forget to implement the code for a prototype/header file item, or b) you forget to pass all the necessary object files to the linker. Neither of those are my problem. Please bear with me as the question I ask is rather long and I think it's beyond a CS101 level of linker stupidity. If it is a stupid CS101 mistake I'm making...
1
613
by: Stephen Horne | last post by:
On Fri, 10 Oct 2008 13:42:57 -0700 (PDT), James Kanze <james.kanze@gmail.comwrote: There are issues with some compilers, but probably only old ones. I remember problems with Borland C++ 5.02. Each DLL ended up with a different heap. It's possible that linker options or similar were to blame, but the easiest thing at the time was to ensure that data always got deleted by the same DLL that newed it - usually not a big
0
9579
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
9420
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
10205
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
10035
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
9984
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,...
1
7401
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
5293
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
3949
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
2
3556
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.