POV-Ray : Newsgroups : povray.programming : C++ problem : Re: C++ problem Server Time
28 Jul 2024 14:20:11 EDT (-0400)
  Re: C++ problem  
From: Thorsten Froehlich
Date: 28 Jul 2001 18:45:20
Message: <3b634080@news.povray.org>
In article <3b632394@news.povray.org> , Warp <war### [at] tagpovrayorg>  wrote:

>   For example many people think that adding a function (ie. method) to a
> class increases the size of the class.

Well, this can be true in case virtual functions are added to a class
containing no virtual functions (and the compiler optimized away the storage
for the vtable pointer if it wasn't used) and when inheriting from other
class(es) class sizes can grow because of vtables and different
this-pointers.

>   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.

>   This is why it's important to know what type of code is generated from
> what you write.

Yes, and it is equally important to know that a linker will warn the user if
it finds duplicate symbols.  After all, without a good linker C++ cannot be
very efficient (i.e. not having duplicate vtables for every file that uses
the same class).

I think this was Peter's assumption.  Fortunately symbol names would be
identical in this case and he would have gotten a proper warning from the
linker if there would have been a problem.

    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

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