POV-Ray : Newsgroups : povray.programming : C++ problem Server Time
28 Jul 2024 18:12:23 EDT (-0400)
  C++ problem (Message 11 to 13 of 13)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Thorsten Froehlich
Subject: Re: C++ problem
Date: 29 Jul 2001 08:26:51
Message: <3b64010b@news.povray.org>
In article <3b63f192@news.povray.org> , Warp <war### [at] tagpovrayorg>  wrote:

> : Yes, and one that isn't very well explained anywhere but in the source code
> : of compilers :-(
>
>   You might already know what virtual inheritance does, but let me explain it
> anyways in case anyone is interested (which I doubt, but for some reason I
> like to write these kind of things... :) ).

I was actually talking about implementing inheritance (and exceptions and
all the other neat C++ features).  For example Stroustrup (some where in one
of his books) claims exceptions can be implemented without some certain
runtime penalty, but he never really explains it or his other comments.

What I mean is that he and all other authors talk a lot about the language,
but I know about no book that actually tells me how to write a good compiler
for it (there seems to be little demand for such a book).  Books about
compiler design on the other hand usually don't talk about these advanced
language specific features.  The beginner books only show basics like how to
generate switch statements, while the advanced books deal mostly with
optimization algorithms...

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Ole Laursen
Subject: Re: C++ problem
Date: 30 Jul 2001 14:27:28
Message: <m3y9p61dli.fsf@bach.composers>
> Virtual functions most probably can't be inlined (although this is one
> detail where I'm not 100% sure).

I some circumstances, they can. For instance when you know the type.
Consider the static

  class_with_virtual_member object;

  object.virtual_member();

as opposed to the dynamic

  base_class_with_virtual_member *object = new derived_class_with_virtual_member;

  object->virtual_member();

I think it might be possible for a smart compiler to optimize even
more complex situations (by tracing through functions, perhaps? I
don't know that much about compilers).

-- 
Ole Laursen
http://sunsite.dk/olau/


Post a reply to this message

From: Ole Laursen
Subject: Re: C++ problem
Date: 30 Jul 2001 14:27:29
Message: <m3u1zu1dcy.fsf@bach.composers>
> > A related misconception is that calling a virtual function is very
> > slow. Yes, it's a bit slower than calling a regular function, but
> > the speed difference is usually one or two CPU clocks, which
> > usually doesn't matter, specially if the function itself takes
> > hundreds of clocks.
> 
> Of course, you assume the vtable is in the cache and the processor supports
> the necessary indirect addressing modes.

I think the most important thing to remember in connection with
virtual functions is that a "hand-crafted" solution will most probably
end up no faster, but a lot more complicated and messy.

The kind of flexibility you get from the dynamically binded functions
simply comes with a cost. Fortunately, that cost probably won't be the
one that slows the program to a crawling halt. :-)

-- 
Ole Laursen
http://sunsite.dk/olau/


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.