Do global variables mean faster code?

后端 未结 14 1974
情深已故
情深已故 2020-12-24 00:58

I read recently, in an article on game programming written in 1996, that using global variables is faster than passing parameters.

Was this ever true, and if so, is

14条回答
  •  半阙折子戏
    2020-12-24 01:40

    In general (but it may depend greatly on compiler and platform implementation), passing parameters mean writing them onto the stack which you would not need with global variable.

    That said, global variable may mean include page refresh in the MMU or memory controller whereas the stack may be located in much faster memory available to the processor...

    Sorry, no good answer for a general question like this, just measure it (and try different scenarios too)

提交回复
热议问题