Efficient C++ Performance Programming Techniques[1]

[入库:2005年11月10日] [更新:2007年10月24日]

本文简介:英文

  We start the performance tour close to home with a real-life example. Chapter 1 is a war story of C++ code that exhibited atrocious performance, and what we did to resolve it. This example will drive home some performance lessons that might very well apply to diverse scenarios.

  Object-oriented design in C++ might harbor a performance cost. This is what we pay for the power of OO support. The significance of this cost, the factors affecting it, and how and when you can get around it are discussed in Chapters 2, 3, and 4. Chapter 5 is dedicated to temporaries. The creation of temporary objects is a C++ feature that catches new C++ programmers off guard. C programmers are not used to the C compiler generating significant overhead "under the covers." If you aim to write high-efficiency C++, it is essential that you know when temporaries are generated by the C++ compiler and how to avoid them. Memory management is the subject of Chapters 6 and 7. Allocating and deallocating memory on the fly is expensive. Functions such as new() and delete() are designed to be flexible and general. They deal with variable-sized memory chunks in a multithreaded environment. As such, their speed is compromised.

  Oftentimes, you are in a position to make simplifying assumptions about your code that will significantly boost the speed of memory allocation and deallocation. These chapters will discuss several simplifying assumptions that can be made and the efficient memory managers that are designed to leverage them. Inlining is probably the second most popular performance tip, right after passing objects by reference. It is not as simple as it sounds. The inline keyword, just like register, is just a hint that the compiler often ignores. Situations in which inline is likely to be ignored and other unexpected consequences are discussed in Chapters 8, 9, and 10.

  Performance, flexibility, and reuse seldom go hand-in-hand. The Standard Template Library is an attempt to buck that trend and to combine these three into a powerful component. We will examine the
performance of the STL in Chapter 11.

  Reference counting is a technique often used by experienced C++ programmers. You cannot dedicate a
book to C++ performance without coverage of this technique, discussed in Chapter 12.

  Software performance cannot always be salvaged by a single "silver bullet" fix. Performance degradation is often a result of many small local inefficiencies, each of which is insignificant by itself. It is the combination that results in a significant degradation. Over the years, while resolving many performance bugs in various C++ products, we have come to identify certain bugs that seem to float to the surface frequently. We divided the list into two sets: coding and design inefficiencies. The coding set contains "low-hanging fruit"—small-scale, local coding optimizations you can perform without needing to understand the overall design. In Chapter 13 we discuss various items of that nature. The second set contains design optimizations that are global in nature. Those optimizations modify code that is spread across the source code, and are the subject of Chapter 14.

  Chapter 15 covers scalability issues, unique performance considerations present in a multiprocessor environment that we don&t encounter on a uniprocessor. This chapter discusses design and coding issues aimed at exploiting parallelism. This chapter will also provide some help with the terminology and concepts of multithreaded programming and synchronization. We refer to thread synchronization concepts in several other places in the book. If your exposure to those concepts is limited, Chapter 15 should help level the playing field.

  Chapter 16 takes a look at the underlying system. Top-notch performance also necessitates a rudimentary understanding of underlying operating systems and processor architectures. Issues such as caching, paging, and threading are discussed here.

Table of Content  i
Copyright v
Dedication  vi
Preface vi
Introduction viii
Roots of Software Inefficiency viii
Our Goal  xi
Software Efficiency: Does It Matter? xi
Terminology  xii
Organization of This Book  xiii

Chapter 1 The Tracing War Story 1
Our Initial Trace Implementation 2
Key Points  7

Chapter 2 Constructors and Destructors 9
Inheritance 9
Composition  18
Lazy Construction  19
Redundant Construction  21
Key Points  25

本文关键:,Efficient C++ Performance Programming Techniques,
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top