Is access to a static function variable slower than access to a global variable?

后端 未结 4 1939
慢半拍i
慢半拍i 2021-02-05 04:21

Static local variables are initialised on the first function call:

Variables declared at block scope with the specifier static have static storage duratio

4条回答
  •  不知归路
    2021-02-05 05:06

    You are conceptually correct of course, but contemporary architectures can deal with this.

    A modern compiler and architecture would arrange the pipeline such that the already-initialised branch was assumed. The overhead of initialisation would therefore incur an extra pipeline dump, that's all.

    If you're in any doubt, check the assembly.

提交回复
热议问题