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
}