C++ templates and optimizing for size @Bisqwit
C++ templates and optimizing for size  @Bisqwit
Uploaded January 2017 | Updated November 2026, 5 days ago
C++ templates are really handy. But guess what? They are not the best solution to every situation. Discover tricks to make the compiler produce more efficient & smaller code.

Twitter: twitter.com/RealBisqwit
Liberapay: liberapay.com/Bisqwit (alternatives at iki.fi/bisqwit/donate.html)
Twitch: twitch.tv/RealBisqwit
Homepage: iki.fi/bisqwit

You can contribute subtitles: youtube.com/timedtext_video?ref=share&v=rUB5Hlm9AaQ

NOTES

To clarify a possible misconception: C++ is firmly founded on the principle of "pay only for what you use". It's not like when you add templates to your program, BAM, it suddenly becomes a gargantuan hog. What I mean is that every time you apply a template to something, it generates a different function or a class for every different set of template parameters that you use in conjunction with that function or class. If you only use one set of template parameters, for example one type, it is bit-per-bit exactly the same outcome as if you just had one function or one class. If you use two different sets of template parameters in conjunction with that function or class, it's like you had two functions or two classes. And so on. It has a multiplicative nature.
If space is a concern, you should try to make sure that one of the terms in that multiplicative expression is as small as possible. Either the number of different template instantations, or the amount of material that the template is applied to. Maybe both.

The music is Over the Horizon, from Space Harrier for X68000.

Source code and other download material related to this video: iki.fi/bisqwit/jkp/cpp_virtual_template

#Bisqwit #Programming #Tutorial #Optimization #C++
C++ templates and optimizing for sizeCreating a Chip8 interpreter/emulator in C++14Obfuscated C programs: IntroductionDecoding a BINK video using libavcodec (remastered)Bisqwit analyses TempleOS & its sole author, Terry A. DavisUr-Quan Masters: No-Starbase Practice Run: UNCUT VERSIONPortal 2 custom map Darkness and LightPortal 2 custom map Darkness and Light (updated)Origin of “Bisqwit”? Married? Font&color theme — Frequently Asked Questions, Part 1/4Portal 2: Extreme Safety Escape ButtonBisqwit Plays: The Talos Principle [4/4] (complete blind 100% all endings)Logic 4: Natural Deduction with Logical Axioms — Tutorial 4/4
Bisqwit |

C++ templates and optimizing for size

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER