User: Password:
|
|
Subscribe / Log in / New account

C++ features and performance

C++ features and performance

Posted Mar 27, 2008 5:34 UTC (Thu) by zlynx (subscriber, #2285)
In reply to: an "old beard" ? by felixfix
Parent article: Striking gold in binutils

Two of the problems you mention are caused because C++ is all about performance.  Any language
feature that will slow things down requires the programmer to explicitly use it.

Array new is a separate function because it has to store the number of elements in the memory
allocation.  Making new and array new the same would waste a size_t for every alloc.

Virtual has to be specified because it slows down the function calls.

I have personal recent experience with virtual.  I used virtual functions in an interface base
class.  After I got done profiling, I did explicit calls to class functions instead of
virtuals in the derived classes and one use of dynamic_cast and then using the pointers with a
template function.  The code was over 20 times faster.

The real killer wasn't the indirect jump, it was how virtuals block inlining and most compiler
optimization, since it can't know what function will really be called.


(Log in to post comments)


Copyright © 2018, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds