不要全局变量意味着更快的code? [英] Do global variables mean faster code?

查看:214
本文介绍了不要全局变量意味着更快的code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了最近,在游戏编程的文章,写于1996年,即使用全局变量是不是通过参数快。

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 this still true today?

推荐答案

简短的回答 - 不,优秀的程序员做code走得更快通过了解并使用相应的工具进行工作,然后在有条不紊地在那里优化其code没有满足他们的要求。

Short answer - No, good programmers make code go faster by knowing and using the appropriate tools for the job, and then optimizing in a methodical way where their code does not meet their requirements.

更长的答案 - 这篇文章,这在我看来没有特别写得很好,是不是在程序加速,但'15方式无论如何一般建议做更快的blit。推断这一般情况下缺少作家的角度,不管你觉得文章的优劣。

Longer answer - This article, which in my opinion is not especially well-written, is not in any case general advice on program speedup but '15 ways to do faster blits'. Extrapolating this to the general case is missing the writer's point, whatever you think of the merits of the article.

如果我一直在寻找表现的意见,我会放在零信任,不识别或显示一个混凝土 code更改为支持在样品$ C $断言的一篇文章中c和不表明测量code可能是一个好主意。如果你不打算展示如何使code好,为什么它包含?

If I was looking for performance advice, I would place zero credence in an article that does not identify or show a single concrete code change to support the assertions in the sample code, and without suggesting that measuring the code might be a good idea. If you are not going to show how to make the code better, why include it?

一些建议是多年过时了 - 远指针不再是PC上的一个问题很久以前。

Some of the advice is years out of date - FAR pointers stopped being an issue on the PC a long time ago.

一个严肃的游戏开发商(或任何其他专业的程序员,对于这个问题)将有关于这样的建议很好笑:

A serious game developer (or any other professional programmer, for that matter) would have a good laugh about advice like this:

您可以取出断言的
  完全,或者你可以添加
  的#define NDEBUG 在编译的最终版本。

You can either take out the assert's completely, or you can just add a #define NDEBUG when you compile the final version.

我给你的忠告,如果你真的希望评估任何这些15提示的优点,而且由于文章是14岁,将编译code在一个现代化的编译器(的Visual C ++ 10讲),并尝试找出使用全局变量(任何地区或其他任何提示)将使其更快。

My advice to you, if you really wish to evaluate the merit of any of these 15 tips, and since the article is 14 years old, would be to compile the code in a modern compiler (Visual C++ 10 say) and try to identify any area where using a global variable (or any of the other tips) would make it faster.

[只是开玩笑 - 我真正的建议是完全忽略这篇文章,并要求具体堆栈溢出的性能问题你打你的工作问题,你解决不了。你得到的答案这种方式将被同行审查,通过例如code或良好的外部证据,并且目前的支持。]

[Just joking - my real advice would be to ignore this article completely and ask specific performance questions on Stack Overflow as you hit issues in your work that you cannot resolve. That way the answers you get will be peer reviewed, supported by example code or good external evidence, and current.]

这篇关于不要全局变量意味着更快的code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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