读书笔记之:Efficient C++ 提高C++性能的编程技术(2003)[++]

第1章 跟踪范例

第2章 构造函数和析构函数

第3章 虚函数

1. 虚函数造成的性能损失

第4章 返回值优化

任何时候只要跳过了对象的创建和清除,就将会获得性能上的收益。返回值优化RVO(Return Value Optimization)是由编译器实现的优化,它用于加速源代码,是通过对源代码进行转化并消除对象的创建来实现的。

1. 按值返回的构造

下面是Complex类:

class Complex{
    friend Complex operator+(const Complex &,const Complex&);
    public:
    Complex(double r=0.0,double i=0.0):real(r),imag(i){}
    Complex(const Complex& c):real(c.real),imag(c.imag){}
    Complex& operator=(const Complex& c){
        if(this!=&c){
            real=c.real;
            imag=c.imag;
        }
        return *this;
    }
    ~Complex(){}
    private:
    double real;
    double imag;
};
Complex operator+(const Complex&a,const Complex& b){
    Complex ret;
    ret.real=a.real+b.real;
    ret.imag=a.imag+b.imag;
    return ret;
}                                                         

 

2. 返回值优化

3. 计算性构造函数

第5章 临时对象

1. 对象的定义

2. 类型不同时的类型转换

3. 按值传递

第6章 单线程内存池

第8章 内联基础

1. 方法调用的代价

引用计数

 

posted @ 2012-08-19 21:54  Mr.Rico  阅读(855)  评论(0编辑  收藏  举报