• Title of article

    Efficient run-time dispatching in generic programming with minimal code bloat

  • Author/Authors

    Lubomir Bourdev، نويسنده , , Jaakko J?rvi، نويسنده ,

  • Issue Information
    ماهنامه با شماره پیاپی سال 2011
  • Pages
    15
  • From page
    243
  • To page
    257
  • Abstract
    Generic programming with C++ templates results in efficient but inflexible code: efficient, because the exact types of inputs to generic functions are known at compile time; inflexible because they must be known at compile time. We show how to achieve run-time polymorphism without compromising performance by instantiating the generic algorithm with a comprehensive set of possible parameter types, and choosing the appropriate instantiation at run time. Applying this approach naïvely can result in excessive template bloat: a large number of template instantiations, many of which are identical at the assembly level. We show practical examples of this approach quickly approaching the limits of the compiler. Consequently, we combine this method of run-time polymorphism for generic programming, with a strategy for reducing the number of necessary template instantiations. We report on using our approach in GIL, Adobe’s open source Generic Image Library. We observed a notable reduction, up to 70% at times, in executable sizes of our test programs. This was the case even with compilers that perform aggressive template hoisting at the compiler level, due to significantly smaller dispatching code. The framework draws from both the generic and generative programming paradigms, using static metaprogramming to fine tune the compilation of a generic library. Our test bed, GIL, is deployed in a real world industrial setting, where code size is often an important factor.
  • Keywords
    Generic programming , C++ templates , Template bloat , Template metaprogramming
  • Journal title
    Science of Computer Programming
  • Serial Year
    2011
  • Journal title
    Science of Computer Programming
  • Record number

    1080178