Re: Is the vptr at the beginning of an object?
On Apr 2, 4:25 pm, Branimir Maksimovic <bm...@hotmail.com> wrote:
On Fri, 2 Apr 2010 08:02:20 -0700 (PDT)
James Kanze <james.ka...@gmail.com> wrote:
On Apr 2, 12:16 pm, "DaveB" <DBu...@usenet.net> 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