Time and Space Implications of Common C++ Programming Idioms

Thesis Proposal

Jeffrey Yasskin


Articles on C++ frequently claim that templates dramatically improve the speed of C++ code. One often-used example is the sort<>() templated function. C’s qsort() function uses the same algorithm but often runs more slowly than sort<>(). It is claimed that this is because templates allow the compiler to better optimize the sorting routine. However, authors also claim that templates dramatically increase the size of compiled code and the time to compile that code. The C qsort() function can be compiled a single time to object code and then reused for every type of array. On the other hand, C++’s sort<>() must be recompiled and included in the executable for every type of array that it is used to sort. This is expected to make programs larger. However, current literature fails to quantify either of these effects.

C++ is a multi-paradigm language, meaning that programmers have a large range of choices when deciding how to solve a particular problem. In my thesis, I plan to examine the tradeoffs programmers implicitly make when they decide to use certain C++ programming idioms rather than others. In particular, I will study the differences between templates and inheritance and between passing arguments by reference and by value. I will produce guidelines about how much each idiom costs in terms of time and space in order that I and other programmers can make informed decisions about which idioms to use for a given project.