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
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.
Who is this book 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.
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
Very nice book full of insights on the use of modern c++ for efficient coding. Nicely written an plenty of examples.
Feefo Verified review
Amazon CustomerFeb 22, 2021
5
I was excited to see how this book covers C++; it has an emphasis on "high performance" and assumes familiarity with C++, and computer systems in general. It dives right into techniques to optimize C++ code, from data structures to memory management to concurrency and more, with lots of code examples to demonstrate concepts. I really liked how the book got close to low-level constructs, such as operating systems and assembly, so that the user could more fully understand what the C++ code was doing. If you haven't worked with C++ before then this might be a dense read. In my opinion, C++ is a pretty complex language and there's lots to unearth, and this book is all about understanding the intricacies of the language. If you want to expand your understanding of C++ and optimize your code through various means, then I think this book does a great job of showing how to do so!
Amazon Verified review
shukailinFeb 17, 2021
5
This book contains several topics including selected algorithm and data structure from STL, memory management, features of C++17 and 20, concurrency, template and more. In some topics, it not only introduces the features but also explain down to machine level so that the reader can get full background on why it has to be done in this way comparing with the other ways. It also mentions several useful tips for essential techniques in C++ which is quite common and useful when doing code review. The book also recommends readers to use https://godbolt.org/ which is a great tool to evaluate performance of different implementation. Also, one can find all the code used in the book on github which is a big plus since readers can easily evaluate it by themselves. I highly recommend this book to the C++ developer who has 2-3 years experience in C++!
Amazon Verified review
hawkinflightJan 13, 2021
5
I recently needed to interact with a C++ code base, and to come up to speed rapidly. Now, after having done that, I am looking at this book to add to what I learned. This is a very solid book. I am very happy that its goal is to focus on how to use the modern version of the language, C++20. There is a lot of material here, and it is thoughtfully and clearly presented.The first three chapters are very inviting and address topics of interest to me:Ch 1) Brief Introduction to C++ - answers "why C++?" and identifies features and drawbacks of the language, as well as the advantages and disadvantages as compared to other languagesCh 2) Essential C++ Techniques - presents modern and essential features of C++, features that one should know to use today's version of the languageCh 3) Analyzing and Measuring Performance - provides excellent material on comparing the efficiency of algorithms and data structures, also covers how to quantify performance by measuring latency and throughput, as well as how to identify hot spots using CPU profilers and how to improve isolated parts of the code by performing microbenchmarkings.The authors indicate that the remaining 11 chapters can be read independently. All of these remaining chapters look good to me, and the next four chapters cover basics which I don't want to skip:Ch 4) Data Structures - emphasizes checking the asymptotic complexity when choosing a data structure, and the importance of the cache level hierarchy in processors, and how it impacts how we need to organize the data for efficient memory accessCh 5) Algorithms - teaches how to use the basic concepts in the Algorithms library, and the advantages of using that library instead of handwriting for-loopsCh 6) Ranges and Views - presents using Range views to construct algorithms. "By using views, we can compose algorithms efficiently, and with a succinct syntax, using the pipe operator." A class can be a view and range adapters can be used to turn ranges into views.Ch 7) Memory Management - emphasizes the importance of understanding how your program uses memory, and advises that if you're facing memory issues, it's a good idea to check what's already available in libraries, since building custom memory managers that are fast, robust, and safe is a challenge. It is mentioned that "what you need" likely already exists, that someone else has probably had the same issue.Some interesting features of the last 7 chapters in the book are:Ch 8) Compile-time programming: demonstrates modern C++ techniques. By using templates, the constexpr, static_assert(), and if constexpr, type traits, and concepts to use metaprogramming to generate functions and values at compile time instead of runtime.Ch 9) Essential Utilities: combines essential classes from the C++ Utility library with containers and metaprogramming to store and iterate over elements of different types, as well as presents an example of implementing reflection, which is not built into C++, though it is planned to be included in future versions of the C++ standard, possibly in C++23.Ch 10) Proxy Objects and Lazy Evaluation - shows how to postpone the execution of certain code until required. Proxy objects can be used to leave exposed interfaces intact and enable optimizations to occur under the hood.Ch 11) Concurrency - provides an introduction to the C++ thread support library, the atomic library, andthe C++ memory model, a short example of lock-free programming, and performance guidelines, including advice on achieving low latency and high throughput. C++20 comes with some useful synchronization primitives: latches, barriers, and semaphore.Ch 12) Coroutines and Lazy Generators - the coroutines added to C++20 are stackless coroutines, though stackful coroutines can be used via third-party libraries. Stackless coroutines are closely related to state machines. A generator is a type of coroutine that yields values back to its caller, and are a way to build lazily evaluated sequences. An example demonstrates how to use C++ coroutines for building generators using the keywords co_yield and co_return.Ch 13) Asynchronous Programming with Coroutines - gives an introduction to the novel feature of asynchronouscoroutines in C++, and introduces a methodology called structured concurrency. It is noted that "although asynchronous programming is the most important driver for having coroutines in C++, there is no support forasynchronous tasks based on coroutines in the standard library", and it is recommended that a library that complements C++20 be used, such as CppCoro or Boost.Asio.Ch 14) Parallel Algorithms - are a way to speed up concurrent programs by utilizing multiple cores. Parallel execution of independent tasks is related to but distinct from concurrency. The parallelism should be abstracted away so that parallelizing code is only a matter of changing a parameter to an algorithm. The importance of parallelism and how to evaluate parallel algorithms is covered.Valuable final comments are provided about performance and the current compiler status for C++20:1) Performance - is an "important aspect of code quality. But too often, performance comes at the expense ofother quality aspects, such as readability, maintainability, and correctness. Solving performance problems usually comes down to a willingness to investigate things further. More often than not, it requires understanding the hardware and underlying OS well enough to be able to draw conclusions from measurement data."2) C++20 compiler support - one of the authors indicates that "a lot of the code presented in this book is only partially supported by the compilers today. I will keep updating the GitHub repository and adding information about compiler support."Really nice book.
Amazon Verified review
Wil COct 25, 2023
5
Written at the right level of depth (not for beginners). Emphasizes modern idioms (C++20). Balanced, thoughtful advice. The comparative language analysis aids in compensation and helps weigh tradeoffs.
Björn Andrist is a freelance software consultant currently focusing on audio applications. For more than 15 years, he has been working professionally with C++ in projects ranging from UNIX server applications to real-time audio applications on desktop and mobile. In the past, he has also taught courses in algorithms and data structures, concurrent programming, and programming methodologies. Björn holds a BS in computer engineering and an MS in computer science from KTH Royal Institute of Technology.
Viktor Sehr is the founder and main developer of the small game studio Toppluva AB. At Toppluva he develops a custom graphics engine which powers the open-world skiing game Grand Mountain Adventure. He has 13 years of professional experience using C++, with real-time graphics, audio, and architectural design as his focus areas. Through his career, he has developed medical visualization software at Mentice and Raysearch Laboratories as well as real-time audio applications at Propellerhead Software. Viktor holds an M.S. in media science from Linköping University.
Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.
If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.
Please Note: Packt eBooks are non-returnable and non-refundable.
Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:
You may make copies of your eBook for your own use onto any machine
You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website?
If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:
Register on our website using your email address and the password.
Search for the title by name or ISBN using the search option.
Select the title you want to purchase.
Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title.
Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook?
If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
To view your account details or to download a new copy of the book go to www.packtpub.com/account
Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.
You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.
What are the benefits of eBooks?
You can get the information you need immediately
You can easily take them with you on a laptop
You can download them an unlimited number of times
You can print them out
They are copy-paste enabled
They are searchable
There is no password protection
They are lower price than print
They save resources and space
What is an eBook?
Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.
When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.
For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.