Chapter 8. Use Better Libraries
A great library is one nobody notices because it is always there, and always has what people need.
Vicki Myron, author of Dewey, the Small Town Library Cat, and librarian of the town of Spencer, Iowa
Libraries are an area of focus in the optimization process. Libraries provide the primitives from which programs are built up. Library functions and classes are often used at the bottom of nested loops, and are thus often hot. Libraries provided by the compiler or operating system command attention to see that they are used efficiently. Project-specific libraries deserve careful design to ensure that they can be used efficiently.
This chapter discusses issues in the use of the C++ standard library, then examines issues in the design of custom libraries that bear on optimization.
Most of Optimized C++ is about tweaking functions to improve performance. This chapter offers instead advice for designers who need to achieve high performance in their initial design, based on my personal experience. Although I introduce this discussion in the context of library design, this section is also a checklist of how good C++ design techniques contribute to good performance.
Optimize Standard Library Use
C++ provides a compact standard library for the following general uses:
-
Determining implementation-dependent behavior, like the largest and smallest values of each numeric type.
-
Functions that might not best be written in C++, like
strcpy()
andmemmove()
.
Get Optimized C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.