• 软件测试技术
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘

字号: | 推荐给好友 上一篇 | 下一篇

Google C++ Style Guide

发布: 2008-7-07 12:32 | 作者: Google | 来源: 领测软件测试网采编 | 查看: 229次 | 进入软件测试论坛讨论

领测软件测试网

I/|0s#xIJB ^+s

Inline Functions

Define functions inline only when they are small, say, 10 lines or less. 软件测试技术门户x9ZTD*Y-D[ x
link

Definition: You can declare functions in a way that allows the compiler to expand them inline rather than calling them through the usual function call mechanism.

a:w FMt$H#|9p

Pros: Inlining a function can generate more efficient object code, as long as the inlined function is small. Feel free to inline accessors and mutators, and other short, performance-critical functions. 软件测试技术门户K H J2p:uY

Cons: Overuse of inlining can actually make programs slower. Depending on a function's size, inlining it can cause the code size to increase or decrease. Inlining a very small accessor function will usually decrease code size while inlining a very large function can dramatically increase code size. On modern processors smaller code usually runs faster due to better use of the instruction cache. 软件测试技术门户 X(w.C7I ZF _9o

Decision:

)y%Io9n1r!^软件测试技术门户l;[I)WG2Pb%y^9xw

A decent rule of thumb is to not inline a function if it is more than 10 lines long. Beware of destructors, which are often longer than they appear because of implicit member- and base-destructor calls! 软件测试技术门户6Ob-pB