Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is the vptr at the beginning of an object?

Reply
Thread Tools

Is the vptr at the beginning of an object?

 
 
red floyd
Guest
Posts: n/a
 
      04-03-2010
On 4/2/2010 2:12 PM, DaveB wrote:
> [insult to a member of the Committee redacted]


*PLONK*


 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      04-03-2010
* red floyd:
> On 4/2/2010 2:12 PM, DaveB wrote:
>> [insult to a member of the Committee redacted]

>
> *PLONK*


Well, there was a bit of insult, true.

On the other hand, I fail to see what James' state as a member of the
standardization committee has to do with anything. I.e. your response is quite
perplexing. It's like "Insult to a human being WITH NOSE redacted".

Appeal to authority (have nose, member of this or that) is a fallacy just as
much as an insult. E.g., by this fallacious measure we'd have to stop discussing
Herbert Schildt's books. Not that I'm comparing you or James to Herbert; that
conclusion would be yet another fallacy (the name of which I've forgotten).


Cheers & hth.,

- Alf

PS: "plonk" is the sound of some serious **** being flushed down the toilet. In
Usenet jargon that means that an otherwise somewhat respected person has been
added to your kill-list. The sound of light-weight **** is just "plink".
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      04-03-2010
On Apr 2, 4:25 pm, Branimir Maksimovic <(E-Mail Removed)> wrote:
> On Fri, 2 Apr 2010 08:02:20 -0700 (PDT)
> James Kanze <(E-Mail Removed)> wrote:
> > On Apr 2, 12:16 pm, "DaveB" <(E-Mail Removed)> wrote:


[...]
> Is there possibility for implementation not to use vptr
> at all?


In theory, at least. As someone (I think it was Alf), all
compilers do use a vptr in practice.

> Eg implementation that would dispatch on 'if's' based on type?
> Eg where indirect function calls are expensive?


The if's would have to be generated at link time, when the
compiler knew all possible types. In practice, some compilers
do do this, but only in time critical loops, as determined by
the profiler. They still maintain the vptr for less critical
sections. In fact, they normally only use the if in cases
where one function is largely predominant, testing whether the
call resolves to that one function, and using the vptr mechanism
if not. And it is normally associated with inlining the most
frequent function, to maximize the associated gains.

--
James Kanze
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      04-03-2010
On Apr 2, 5:33 pm, red floyd <(E-Mail Removed)> wrote:
> On Apr 2, 8:25 am, Branimir Maksimovic <(E-Mail Removed)> wrote:


[...]
> > Is there possibility for implementation not to use vptr
> > at all? Eg implementation that would dispatch on 'if's'
> > based on type? Eg where indirect function calls are expensive?


> I can imagine a vptr-less implementation, where each virtual
> function is implemented as a pointer within each object,
> rather than a vtbl implementation, where such pointers are a
> per-class thing. So to talk about the vptr at all is
> nonsense, especially since it isn't mandated.


A more likely implementation would be to use a hash table
mapping the object's address to a vtbl, at least based on the
suggestions I've heard. But I rather like your idea; a compiler
could use it whenever the number of virtual functions is less
that some specific number, switching to the vptr if it is
larger. You obviously don't want to use it for objects with
hundreds of virtual functions, but some common uses will only
have one or two virtual functions, and it might represent a
significant gain in performance in such cases.

--
James Kanze

 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      04-03-2010
On Apr 3, 1:40 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> * red floyd:


> > On 4/2/2010 2:12 PM, DaveB wrote:
> >> [insult to a member of the Committee redacted]


> > *PLONK*


> Well, there was a bit of insult, true.


> On the other hand, I fail to see what James' state as a member
> of the standardization committee has to do with anything.


I don't think it does (especially since I haven't been
particularly active lately). On the other hand, calling an
accurate and precise description of the issues "technical
gibberish" gives a very good idea of the competence (technical
and otherwise) of the poster. One gets the feeling that he
prefers to ignore real issues.

--
James Kanze
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      04-03-2010
* James Kanze:
> On Apr 2, 4:25 pm, Branimir Maksimovic <(E-Mail Removed)> wrote:
>> On Fri, 2 Apr 2010 08:02:20 -0700 (PDT)
>> James Kanze <(E-Mail Removed)> wrote:
>>> On Apr 2, 12:16 pm, "DaveB" <(E-Mail Removed)> wrote:

>
> [...]
>> Is there possibility for implementation not to use vptr
>> at all?

>
> In theory, at least. As someone (I think it was Alf), all
> compilers do use a vptr in practice.


Yes, I wrote that.

But regarding the question at hand, one alternative is some other kind of object
-> type association, and an actual search up the base class chains, which is
roughly how the C++ standard specifies the effect of a virtual call, and is
roughly how Smalltalk actually did the dispatching.

And I think Borland C++ once did that for methods outfitted with (language
extension) integer id's; it was an event handling scheme tailored for Windows
window messages. Or perhaps it was only in Borland Pascal. But anyway.


Cheers,

- Alf
 
Reply With Quote
 
DaveB
Guest
Posts: n/a
 
      04-04-2010
James Kanze wrote:
> On Apr 3, 1:40 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
>> * red floyd:

>
>>> On 4/2/2010 2:12 PM, DaveB wrote:
>>>> [insult to a member of the Committee redacted]

>
>>> *PLONK*

>
>> Well, there was a bit of insult, true.

>
>> On the other hand, I fail to see what James' state as a member
>> of the standardization committee has to do with anything.

>
> I don't think it does (especially since I haven't been
> particularly active lately). On the other hand, calling an
> accurate and precise description of the issues "technical
> gibberish" gives a very good idea of the competence (technical
> and otherwise) of the poster. One gets the feeling that he
> prefers to ignore real issues.


The question remains open. Maybe someone NOT in the priesthood of
technobabblery can answer it.


 
Reply With Quote
 
Bo Persson
Guest
Posts: n/a
 
      04-04-2010
DaveB wrote:
> James Kanze wrote:
>> On Apr 3, 1:40 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
>>> * red floyd:

>>
>>>> On 4/2/2010 2:12 PM, DaveB wrote:
>>>>> [insult to a member of the Committee redacted]

>>
>>>> *PLONK*

>>
>>> Well, there was a bit of insult, true.

>>
>>> On the other hand, I fail to see what James' state as a member
>>> of the standardization committee has to do with anything.

>>
>> I don't think it does (especially since I haven't been
>> particularly active lately). On the other hand, calling an
>> accurate and precise description of the issues "technical
>> gibberish" gives a very good idea of the competence (technical
>> and otherwise) of the poster. One gets the feeling that he
>> prefers to ignore real issues.

>
> The question remains open. Maybe someone NOT in the priesthood of
> technobabblery can answer it.


I think we have already seen the answer:

In some cases it might be that a vptr is the first member of an
object. The only exception is when it is not, or when there isn't
exactly one vptr in the object.




 
Reply With Quote
 
Robert Fendt
Guest
Posts: n/a
 
      04-04-2010
And thus spake Paul N <(E-Mail Removed)>
Fri, 2 Apr 2010 03:20:07 -0700 (PDT):

> Just out of curiosity, I thought the compiler was obliged to put the
> first member at offset zero? If so (and it could well be I'm wrong
> here...) then it must put the vptr (assuming there is one) somewhere
> else?


Only for classes where interoperability with C is provided ('POD
types'). In practice, it usually works that way as long as no
virtual functions are involved, though the constraints on PODs
are a bit more severe, IIRC.

Regards,
Robert

 
Reply With Quote
 
DaveB
Guest
Posts: n/a
 
      04-05-2010
Bo Persson wrote:
> DaveB wrote:
>> James Kanze wrote:
>>> On Apr 3, 1:40 pm, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
>>>> * red floyd:
>>>
>>>>> On 4/2/2010 2:12 PM, DaveB wrote:
>>>>>> [insult to a member of the Committee redacted]
>>>
>>>>> *PLONK*
>>>
>>>> Well, there was a bit of insult, true.
>>>
>>>> On the other hand, I fail to see what James' state as a member
>>>> of the standardization committee has to do with anything.
>>>
>>> I don't think it does (especially since I haven't been
>>> particularly active lately). On the other hand, calling an
>>> accurate and precise description of the issues "technical
>>> gibberish" gives a very good idea of the competence (technical
>>> and otherwise) of the poster. One gets the feeling that he
>>> prefers to ignore real issues.

>>
>> The question remains open. Maybe someone NOT in the priesthood of
>> technobabblery can answer it.

>
> I think we have already seen the answer:
>
> In some cases it might be that a vptr is the first member of an
> object. The only exception is when it is not, or when there isn't
> exactly one vptr in the object.


I didn't see that one, and it points the direction to the answer I was
looking for. I was looking for someone who knows about a number of
"mainstream" compilers and can expound on the implementations of vptrs in
those. The assumption, or hope, being that "all" compilers use vptrs
rather than some other way. I asked more generally than I needed to know,
but the added information from someone who had it was easy enough to ask
for. Particularly, though, I wanted to know about gcc because between
that and VC, I my target platform is covered by those 2, and I am using
PLATFORM loosely here. I don't use multiple inheritance and am not
worried about anything strange happening in some remote corner case, and
if I was, I would have given more information than just "where is that
dang vptr!?". What I am doing that makes me need that information is not
relevant, and none of anyone's business unless I volunteer it. For
someone (not you in this post) to say that the question has been finely
answered, while I still have not the information I solicited, is pompous,
or at least seems so with a high degree of certainty, not to let a
sleeping dog alone, of course.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
index of string from beginning of line vs beginning of file Jesse B. Ruby 9 03-27-2010 04:04 PM
vptr Rahul C++ 3 11-04-2007 12:03 PM
A basic doubt on VPTR and VTABLES Subhransu Sahoo C++ 4 11-07-2006 12:42 PM
Explanation of Vptr and V-table pai C++ 4 10-18-2006 02:09 PM
What is Data Type of Vptr pointer Veeru C++ 7 09-15-2006 10:00 AM



Advertisments