C ++全局变量的性能 [英] C++ performance of global variables

查看:151
本文介绍了C ++全局变量的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

澄清:我知道全局变量有多坏,何时不使用它们)

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


  • 访问/在编译的C ++程序中设置全局变量和局部变量?

推荐答案

完全取决于您的机器架构。全局变量通过单个已知地址访问,而局部变量通常通过索引地址寄存器访问。两者之间的差异很大的机会是非常遥远的,但如果你认为这很重要,你应该为你的目标架构写一个测试,并测量差异。

That would depend entirely on your machine architecture. Global variables are accessed via a single known address, whereas local variables are typically accessed by indexing off an address register. The chances of the difference between the two being significant is extremely remote, but if you think it will be important, you should write a test for your target architecture and measure the difference.

这篇关于C ++全局变量的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆