Performance about C++ code

1,函数声明中的类参数使用引用传递而非值传递,避免拷贝构造函数的调用。
2,The variable should be declared when it will be used.
3,declaration and construction at the same time.
  someclass obj;  //default construction
  obj = xyz; //operater =

  should be somclass obj=xyz; // copy construction only
4,using initializing list is better than construction function.
  Avoiding the allocation from heap???
  someclass::someclass(int x)
  {
     foo = x;
   }
 
  someclass::someclass(int x):foo(x)

5,"+=" is better than " + "
  foo1 = foo1 + foo2;  // a temp variable would be used
  foo1 += foo2; //no temp variable

6, ++x is better than x++
   The temp variable would be used in x++

7,be careful to use the inline function
  If the inline function is very large, the compiler would refuse inlining. and would produce a independent local function in every cpp file who include the inline function.

8,How to reduce the size of memory being used
  1) be careful to use the order of byte.
  2)If it is possible, union is a good choice when  only one member would be used in a struct.

9,How to improve the speed
  1) using the register variable
    void f()
    {
       int *p = new int[3000];
       register int *p2=p;
       for ( register int j=0; j<3000; j++)
         *p2++=0;
       delete []p;
    }
   2) using const to the object never changed
   3) compiler close the supporting to RTTI and exception.
      Because compiler would insert specific code for these functions.

10, Performance improvement should focused on the released version instead debug version.
    Debuging and optimization are differnt target
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值