C++ performance of global variables

前端 未结 9 1903
谎友^
谎友^ 2021-01-04 07:32

For clarification: I know how evil globals are and when not to use them :)

  • Is there any performance penalty when accessing/setting a global variable vs. a loca
9条回答
  •  轮回少年
    2021-01-04 07:41

    There are a number of compiler optimisations that are possible with local variables but not with global variables, so in some cases you might see a difference in performance. I doubt that your global variable is being accessed in a performance-critical loop though (very bad design if it is !) so it's probably not going to be an issue.

提交回复
热议问题