[ros-kernel] C++

art yerkes ayerkes at speakeasy.net
Thu Mar 11 08:57:25 CET 2004


Although I don't have as much experience with drivers, etc, as the rest, I do
have lots of experience with the C++ code generator.  While it is 'crappy' in
a purely theoretical sense, it's not doing anything that wouldn't be obvious,
it's just doing everything in the most obvious way (which isn''t to say the
fastest).

>From my experience in streaming servers (my day job project) which are 
compiled on g++, it's very easy to predict where g++ will generate strange
code; it's all the things that were completely broken in the last version.
I.E. If a certain template caused a 'unable to spill' error before, it
generates crappy code now.

-- What to do about it, to write fast C++ code --

Turn on gcc optimizations.  Experiment with specific processor flags.  One
type of optimization will often yield tens of points of performance for a 
program that has tight, hungry loops.

Don't use 'std::string' in the tight areas.  Contrary to popular belief,
C++ actually has C in it.  Use C for mixing audio, colorspace conversion,
packet headers, etc.  Alternately, don't bother using C for maintaining
aunt betty's cake recipies.

Use the profiler.  Often one or two small functions will save loads.

Don't underestimate the power of some modern but mostly portable operating
system features.  If you can expect to have virtual memory everywhere,
use it and don't appologise.
-- 
IBM had little or no expertise on Intel processors.
 -- paragraph 54, SCO v IBM, second amended complaint
No matter how cynical you become, it's never enough to keep up.
 -- Lily Tomlin


More information about the Ros-kernel mailing list