##### Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

# Symbian基本规范:代码效率

beover1984 在 19 Aug 2007 创建

Ø 除了基本类型避免值拷贝。

Ø 应该在堆上而不是栈上创建任何大的对象或数组。

Ø 通过适当的域最小化自动变量的生命周期。

{
TBigObject Object1;
TBigObject Object2;
TBigObject Object3;

GetTwoObjectValues(Object1,Object2);
Object3=SumObjects(Object1,Object2);
}

void ABetterFunction()
{
TBigObject Object1;

GetTotalObjectValues(Object1);
}

void GetTotalObjectValues(TBigObject &aObject)
{
TBigObject Object1;
TBigObject Object2;

GetTwoObjectValues(Object1,Object2);
aObject=SumObjects(Object1,Object2);
}

void FunctionOne(TInt aInt=0);

FunctionOne();

void FunctionOne()
{
FunctionOne(0);
}

class CXxx : public CBase,public MYyy {...};

Func((MYyy* aM)(cp==NULL ? NULL : (TUint8*)cp+sizeof(CBase)));

TReal a = (TReal)aTop;
TReal b = (TReal)aBottom;
TReal c = a/b;
TReal result;
Math::Round(result,c,0);
return (TInt)result;

return((2*aTop+aBottom)/(2*aBottom));

inline ConEnv() const { return iConEnv; };

Ø T类的简单构造函数：

inline TPoint::TPoint(TInt aX, TInt aY) { iX=aX; iY=aY; };

Ø 在瘦模板中的用法：参考：SDK» Developer Library » Symbian OS Guide » Essential idioms » Thin templates Ø 那些映射其它运算的函数，并且确定其中的运算符，函数或模板的定义不轻意改变，例如：

template <class T> inline T Min(T aLeft,T aRight)
{ return(aLeft<aRight ? aLeft : aRight); }

if (iX)
delete iX;