{"id":6257,"date":"2022-05-27T08:11:57","date_gmt":"2022-05-27T15:11:57","guid":{"rendered":"https:\/\/cppcon.org\/?page_id=6257"},"modified":"2024-04-04T21:31:56","modified_gmt":"2024-04-05T04:31:56","slug":"class-2022-thinking-small","status":"publish","type":"page","link":"https:\/\/cppcon.org\/class-2022-thinking-small\/","title":{"rendered":"Thinking Small [2022 class archive]"},"content":{"rendered":"<p><em>Thinking Small<\/em> is a two-day <strong>onsite<\/strong> training course with programming examples, taught by <strong>Patrice Roy<\/strong>. \u00a0It is offered at the\u00a0<a class=\"docs-creator\" href=\"https:\/\/cppcon.org\/venue\/\">Gaylord Rockies<\/a> from 09:00 to 17:00 Aurora time (MDT) on Saturday and Sunday, September 10th and 11th, 2022 (immediately <strong>prior to<\/strong> the conference). Lunch is included.<\/p>\n<h2>Course Description<\/h2>\n<p>Maybe you are someone who, at least on occasion, needs to think small when coding:<\/p>\n<ul>\n<li>You write programs that need to fit in limited memory, or that are big to the point where available memory becomes a problem<\/li>\n<li>You care about speed and the way your code and your data fit in cache<\/li>\n<li>When your projects near their shipping deadline, you and your team are scrambling for the last few remaining bytes available<\/li>\n<li>You work in the kind of industry where, once the code\u2019s ready to ship, more space in persistent storage or in memory means additional resources to make the product more enticing<\/li>\n<\/ul>\n<p>Today, with code, small often (not always, of course) means fast. For that reason, this course, titled Thinking Small, seeks to bring its audience techniques that will help write programs that lead to smaller and faster binaries (sometimes one, sometimes the other, ideally both) using standard C++.<\/p>\n<h2>Prerequisites<\/h2>\n<p>In order to benefit from this class, you will need:<\/p>\n<ul>\n<li>To be familiar with &#8220;modern&#8221; C++, the word &#8220;modern&#8221; being taken in the sense of &#8220;C++11 and later&#8221;. You don&#8217;t need to be an expert, but having used such things as lambdas and constexpr beforehand will make the class material feel less&#8230; alien<\/li>\n<li>To have a laptop with a compiler that supports C++17, ideally C++20 as there are some gems in there for our purposes. We will strive to limit ourselves to portable C++ code, but we will consider C++17 to be portable since all major compilers support it today\u2026 and because there\u2019s so much to enjoy in today\u2019s language!<\/li>\n<li>To be willing to do in-class exercises, and to discuss tricks and techniques with your instructor and colleagues in a friendly manner. In such training sessions, part of the experience comes from meeting other interested (and interesting!) individuals, and sharing knowledge and tricks<\/li>\n<\/ul>\n<p>If you come from another language than C++, make sure to inform Patrice such that he can better accompany you in your in-class experience.<\/p>\n<h3>Target Audience<\/h3>\n<p>The target audience is intermediate-level developers who:<\/p>\n<ul>\n<li>Are familiar with modern C++, meaning C++11 and more in this case, without necessarily being experts<\/li>\n<li>Work in resource-constrained application domains<\/li>\n<li>Want to get a better understanding of how standard C++ as it exists today can help you meet these constraints<\/li>\n<\/ul>\n<p>Junior developers can benefit from this course if they want to develop skills appropriate to the target application domain. Developers coming to C++ from another language might find the course surprisingly useful due to the (potentially radical) differences between the object model of C++ and these other languages. More advanced developers might also enjoy this course if looking for a greater familiarity with modern C++ and its usefulness in their daily tasks. Make sure to examine the Selected Approach and Expected Contents sections below to ensure you make the right choice for your needs.<\/p>\n<p>By concentrating on standard C++, this course will avoid most compiler-specific and operating system-specific techniques that one can use to achieve smaller or faster code. For that reason, if you are looking for a better knowledge of such tricks (compiler intrinsics, inline assembly, compiler options, specific system calls, etc.), this course might not be what you want. Finally, if you are working in an application domain where there are abundant resources and one can always add hardware to fix problems, you might be wondering what this course is about at all; this doesn\u2019t mean you would not enjoy it, but keeping an open mind would be particularly important.<\/p>\n<p>This course will address concurrency issues on occasion, and will use templates quite frequently. Familiarity with concurrent programming, while not necessary, will help participants benefit more from the experience, and familiarity with templates is recommended.<\/p>\n<h3>Requirements<\/h3>\n<p>Since the class will involve problem-solving exercises, participants must bring their laptops (or equivalent development tool) and at least one recent C++ compiler of their choice; compilers that support C++\u00a017 are obviously preferable given the subject matter. As mentioned previously, we will strive to constrain ourselves to standard C++ only, and will avoid non-portable or platform-specific code as much as possible.<\/p>\n<p>Note that, since there is a variety of target compilers for the target application domains, and that not all of them support all modern C++ features one could hope for, we will sometimes cover techniques to work around these missing features or emulate them.<\/p>\n<p>The format for this course will be a combination of lecture-style presentation of features and tricks and exercise solving. We will typically start with a concrete problem to solve, and a minimal objective to achieve, and work towards reaching that objective for some short time. A presentation of potential solutions will follow, accompanied by a discussion where participants\u2019 input is encouraged.<\/p>\n<h2>Course Topics<\/h2>\n<p>Topics covered in this course include:<\/p>\n<ul>\n<li>How we will measure execution time\n<ul>\n<li>brief overview of lambdas, variadics, move semantics and perfect forwarding<\/li>\n<\/ul>\n<\/li>\n<li>Brief overview of CPU caches and their impact on program speed\n<ul>\n<li>false sharing, cost of concurrent read and write memory accesses, impact of unpredictable memory accesses, relation to size of objects, relation to memory layout, etc.<\/li>\n<li>what the standard library provides to help one portably benefit from cache size, particularly since C++17<\/li>\n<\/ul>\n<\/li>\n<li>Object size and layout basics:\n<ul>\n<li>sizeof, alignof, alignas<\/li>\n<li>composite objects<\/li>\n<li>arrays<\/li>\n<li>we will look at both what is guaranteed by the standard and what is not (sometimes, we take things done by a specific compiler vendor as standard even if it is not)<\/li>\n<\/ul>\n<\/li>\n<li>Simple but sometimes dirty tricks to reduce object size: member variable ordering, strong enumerations, bitfields (with all the problems they bring), unions<\/li>\n<li>Impact (or lack thereof) of generic programming on program size, and how to reduce such costs.<\/li>\n<li>Low-level memory management:\n<ul>\n<li>placement new<\/li>\n<li>writing arenas<\/li>\n<li>allocators (and how the rules have changed between versions of the language)<\/li>\n<li>stack allocation<\/li>\n<li>rules for object lifetime and avoiding undefined behavior when playing tricks with it<\/li>\n<\/ul>\n<\/li>\n<li>The small object optimization:\n<ul>\n<li>what it is, how it is useful, and how it can be implemented<\/li>\n<li>concrete examples (string, function, writing your own compact delegate)<\/li>\n<\/ul>\n<\/li>\n<li>Some (potentially) compact standard containers and utilities, including bitset and the useful-but-unfortunately-named vector&lt;bool&gt;, as well as recent utilities such as optional and variant.<\/li>\n<li>Other tricks to make things small and fast: interruptible tasks, turning arrays-of-structs into structs-of-arrays, when to use reinterpret_cast, when to use constexpr, etc.<\/li>\n<\/ul>\n<h2><a href=\"https:\/\/cppcon2022.eventbrite.com\/\">Register Here<\/a><\/h2>\n<h2>Course\u00a0Instructor<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-891 alignleft\" src=\"https:\/\/cppcon.org\/wp-content\/uploads\/2015\/11\/PatriceRoy-300x300.jpeg\" alt=\"Patrice Roy\" width=\"175\" height=\"175\" srcset=\"https:\/\/cppcon.org\/wp-content\/uploads\/2015\/11\/PatriceRoy-300x300.jpeg 300w, https:\/\/cppcon.org\/wp-content\/uploads\/2015\/11\/PatriceRoy-150x150.jpeg 150w, https:\/\/cppcon.org\/wp-content\/uploads\/2015\/11\/PatriceRoy.jpeg 320w\" sizes=\"auto, (max-width: 175px) 100vw, 175px\" \/><\/p>\n<p><strong>Patrice Roy<\/strong> has been playing with C++, either professionally, for pleasure or (most of the time) both for over 30 years. After a few years doing R&amp;D and working on military flight simulators, he moved on to academics and has been teaching computer science since 1998. Since 2005, he\u2019s been involved more specifically in helping graduate students and professionals from the fields of real-time systems and game programming develop the skills they need to face today\u2019s challenges.<\/p>\n<p>He\u2019s been a participating member in the ISO C++ Standards Committee since late 2014 and has been involved with the ISO Programming Language Vulnerabilities since late 2015. He has five kids, and his wife ensures their house is home to a continuously changing numbers of cats, dogs and other animals.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Thinking Small is a two-day onsite training course with programming examples, taught by Patrice Roy. \u00a0It is offered at the\u00a0Gaylord Rockies from 09:00 to 17:00 Aurora time (MDT) on Saturday and Sunday, September 10th and 11th, 2022 (immediately prior to the conference). Lunch is included. Course Description Maybe you are someone who, at least on [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-6257","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/cppcon.org\/wp-json\/wp\/v2\/pages\/6257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cppcon.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/cppcon.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/cppcon.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cppcon.org\/wp-json\/wp\/v2\/comments?post=6257"}],"version-history":[{"count":3,"href":"https:\/\/cppcon.org\/wp-json\/wp\/v2\/pages\/6257\/revisions"}],"predecessor-version":[{"id":8497,"href":"https:\/\/cppcon.org\/wp-json\/wp\/v2\/pages\/6257\/revisions\/8497"}],"wp:attachment":[{"href":"https:\/\/cppcon.org\/wp-json\/wp\/v2\/media?parent=6257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}