Coding Practices which enable the compiler/optimizer to make a faster program

后端 未结 30 1940
一个人的身影
一个人的身影 2020-12-02 03:24

Many years ago, C compilers were not particularly smart. As a workaround K&R invented the register keyword, to hint to the compiler, that maybe it woul

30条回答
  •  时光说笑
    2020-12-02 03:58

    use const correctness as much as possible in your code. It allows the compiler to optimize much better.

    In this document are loads of other optimization tips: CPP optimizations (a bit old document though)

    highlights:

    • use constructor initialization lists
    • use prefix operators
    • use explicit constructors
    • inline functions
    • avoid temporary objects
    • be aware of the cost of virtual functions
    • return objects via reference parameters
    • consider per class allocation
    • consider stl container allocators
    • the 'empty member' optimization
    • etc

提交回复
热议问题