C++ performance of global variables

前端 未结 9 1923
谎友^
谎友^ 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:58

    Strictly speaking, no.

    Some things to consider: Global variables increase the static size of your program in memory. If access to the variable needs to be synchronized, that would incur some performance overhead.

提交回复
热议问题