This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Little Lessons....


Here are some little lessons I have been learning of late...

1) libstdc++ is devilishly cunning w.r.t small object allocation. ie. Many 
   many malloc's and free's simply don't happen as the cunning small 
   object allocators optimise them away - conversely, memory debuggers are sometimes 
   not as helpful as you would hope...(Still invaluable tools, but nasties
   involving invalidated iterators can be missed.)

2) Inline functions in C++ are formally equivalent to type safe, scope 
   safe macros. Therefore the libstdc++ is using them _very_ heavily. Very 
   very heavily. Unfortunately they are only inlined at -O3 optimization 
   level (unless you say -finline-functions) ie. Optimization these days 
   can easily double the speed of a program, whereas in the bad old days 
   optimization was regard as a tweak to drag another 10% speed out of 
   your program.

3) Some people are still foolish enough not to compile with -Wall and -W 
   on. 

   Stupid stupid rat creatures. 

   If some warning floods you from a source you can't fix, you can silence
   that with -Wno-whatever-the-warning-you-cant-fix-is, but leave the rest
   on.
   
4) Valgrind is _very_ useful for C++ programmers as the compiler cannot 
   detect uninitialised instance variables. Valgrind + Unit tests is a 
   real bug killer. And once you've killed them, they stay dead..

5) Use ostringstream in preference to +'ing lots of strings together. The 
   sstream stuff seems to be very good these days.


-- 


John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email : john.carter@tait.co.nz
New Zealand

Good Ideas:
Ruby                 - http://www.ruby-lang-org - The best of perl,python,scheme without the pain.
Valgrind             - http://developer.kde.org/~sewardj/ - memory debugger for x86-GNU/Linux
Free your books      - http://www.bookcrossing.com



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]