C++ Tips: Difference between revisions

Jump to navigation Jump to search
427 bytes added ,  7 October 2009
(Created page with 'This page collects various tips and common pitfalls when working with the C++ code. Some are generic, others are FlightGear specific == Primitive Types == * Use the SimGear pri…')
 
Line 13: Line 13:
== C++ Efficiency ==
== C++ Efficiency ==


* Always pass aggregate types by (const) reference, especially STL containers, <tt>string</tt> or mathematical tuples such as <tt>SGQuat</tt> or <tt>SGVec3</tt>. String copying in particular is common and leads to many wasteful <tt>malloc</tt> and <tt>free</tt> calls.
Rather than duplicate the many fine works in this area, it's likely you should find and read 'Effective-C++', 'More Effective-C++' and 'Effective STL', all by Scott Meyers. The most critical points are repeated here, though.
 
* Always pass aggregate types by (const) reference, especially STL containers, <tt>string</tt> or mathematical tuples such as <tt>SGQuat</tt> or <tt>SGVec3</tt>. String copying in particular is common and leads to many wasteful <tt>malloc</tt> and <tt>free</tt> calls. Passing STL containers by value is extremely wasteful, as is returning them by value - pass them into methods by a reference, and out the same way. This avoids any container copying at all, hopefully.


== Pitfalls ==
== Pitfalls ==
580

edits

Navigation menu