C++ High Performance
Book information
Description
A comprehensive guide to help aspiring and professional C++ developers elevate the performance of their apps by allowing them to run faster and consume fewer resources Key Features Updated to C++20 with completely revised code and more content on error handling, benchmarking, memory allocators, and concurrent programming Explore the latest C++20 features including concepts, ranges, and coroutines Utilize C++ constructs and techniques to carry out effective data structure optimization and memory management Book Description C++ High Performance, Second Edition guides you through optimizing the performance of your C++ apps. This allows them to run faster and consume fewer resources on the device they're running on without compromising the readability of your codebase. The book begins by introducing the C++ language and some of its modern concepts in brief. Once you are familiar with the fundamentals, you will be ready to measure, identify, and eradicate bottlenecks in your C++ codebase. By following this process, you will gradually improve your style of writing code. The book then explores data structure optimization, memory management, and how it can be used efficiently concerning CPU caches. After laying the foundation, the book trains you to leverage algorithms, ranges, and containers from the standard library to achieve faster execution, write readable code, and use customized iterators. It provides hands-on examples of C++ metaprogramming, coroutines, reflection to reduce boilerplate code, proxy objects to perform optimizations under the hood, concurrent programming, and lock-free data structures. The book concludes with an overview of parallel algorithms. By the end of this book, you will have the ability to use every tool as needed to boost the efficiency of your C++ projects. What you will learn Write specialized data structures for performance-critical code Use modern metaprogramming techniques to reduce runtime calculations Achieve efficient memory management using custom memory allocators Reduce boilerplate code using reflection techniques Reap the benefits of lock-free concurrent programming Gain insights into subtle optimizations used by standard library algorithms Compose algorithms using ranges library Develop the ability to apply metaprogramming aspects such as constexpr, constraints, and concepts Implement lazy generators and asynchronous tasks using C++20 coroutines Who this book is for If you're a C++ developer looking to improve the efficiency of your code or just keen to upgrade your skills to the next level, this book is for you. Table of Contents A Brief Introduction to C++ Essential C++ Techniques Analyzing and Measuring Performance Data Structures Algorithms Using Ranges and Views Memory Management Compile-Time Programming Essential Utilities Proxy Objects and Lazy Evaluation Concurrency Coroutines and Lazy Generators Asynchronous Programming with Coroutines Parallel STL Algorithms Cover Copyright Packt Page Contributors Table of Contents Preface Chapter 1: A Brief Introduction to C++ Why C++? Zero-cost abstractions Programming languages and machine code abstractions Abstractions in other languages The zero-overhead principle Portability Robustness C++ of today C++ compared with other languages Competing languages and performance Non-performance-related C++ language features Value semantics Const correctness Object ownership Deterministic destruction in C++ Avoiding null objects using C++ references Drawbacks of C++ Libraries and compilers used in this book Summary Chapter 2: Essential C++ Techniques Automatic type deduction with the auto keyword Using auto in function signatures Forwarding the return type using decltype(auto) Using auto for variables A const reference A mutable reference A forwarding reference Practices for ease of use Const propagation for pointers Move semantics explained Copy-construction, swap, and move Copy-constructing an object Resource acquisition and the rule of five Named variables and rvalues Default move semantics and the rule of zero Rule of zero in a real code base A common pitfall – moving non-resources Applying the && modifier to class member functions Don't move when copies are elided anyway Pass by value when applicable Cases where pass-by-value is not applicable Moving constructor parameters Designing interfaces with error handling Contracts Class invariants Maintaining contracts Error handling Programming error or runtime error? Programming errors (bugs) Recoverable runtime errors Function objects and lambda expressions The basic syntax of a C++ lambda The capture clause Capture by reference versus capture by value Similarities between a lambda and a class Initializing variables in capture Mutating lambda member variables Capture all Assigning C function pointers to lambdas Lambda types Lambdas and std::function Implementing a simple Button class with std::function Performance consideration of std::function Generic lambdas Summary Chapter 3: Analyzing and Measuring Performance Asymptotic complexity and big O notation Growth rates Amortized time complexity What to measure and how? Performance properties Speedup of execution time Performance counters Performance testing — best practices Knowing your code and hot spots Instrumentation profilers Sampling profilers Microbenchmarking Amdahl's law Pitfalls of microbenchmarking A microbenchmark example Summary Chapter 4: Data Structures The properties of computer memory The standard library containers Sequence containers Vectors and arrays Deque List and forward_list The basic_string Associative containers Ordered sets and maps Unordered sets and maps Container adaptors Priority queues Using views Avoiding copies with string_view Eliminating array decay with std::span Some performance considerations Balancing between complexity guarantees and overhead Knowing and using the appropriate API functions Parallel arrays Summary Chapter 5: Algorithms Introducing the standard library algorithms Evolution of the standard library algorithms Solving everyday problems Iterating over a sequence Generating elements Sorting elements Finding elements Finding using binary search Testing for certain conditions Counting elements Minimum, maximum, and clamping Iterators and ranges Introducing iterators Sentinel values and past-the-end iterators Ranges Iterator categories Features of the standard algorithms Algorithms do not change the size of the container Algorithms with output require allocated data Algorithms use operator==() and operator
Similar books
C++ High Performance: Master the art of optimizing the functioning of your C++ code, 2nd Edition. Code
2020 · ZIP
C++ High Performance
2020 · EPUB
C++ High Performance
2020 · MOBI
C++ High Performance
2018 · PDF
C++ High Performance
2018 · PDF
C++ High Performance
2018 · PDF
MySQL® Notes for Professionals book
2018 · PDF
MrExcel 2022: Boosting Excel
2022 · PDF