在64位环境(C ++)中32位整数的性能 [英] Performance of 32-bit integers in a 64-bit environment (C++)

查看:241
本文介绍了在64位环境(C ++)中32位整数的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经开始编译我们的一些应用程序的32位和64位版本。我的项目中的一个人鼓励我们将所有的32位整数切换到64位等效,即使这些值保证适合32位空间。例如,我有一个值,保证永远不会超过10,000,我存储在一个unsigned int。他的建议是将其切换为size_t,以便在64位环境中扩展为64位,即使我们不再需要额外的空间。他说使用64位变量将加速应用程序,而不考虑每个变量中存储的值。他是对的吗?它的结果是很多工作,我不急于投入努力,如果它没有实际上有所作为。

We've started compiling both 32- and 64-bit versions of some of our applications. One of the guys on my project is encouraging us to switch all of our 32-bit integers to their 64-bit equivalents, even if the values are guaranteed to fit in a 32-bit space. For example, I've got a value that is guaranteed to never exceed 10,000 which I'm storing in an unsigned int. His recommendation is to switch this to a size_t so that it expands to 64 bits in a 64-bit environment, even though we'll never need the extra space. He says that using 64-bit variables will speed up the application regardless of the values stored in each variable. Is he right? It's turning out to be a lot of work, and I'm not anxious to put in the effort if it doesn't actually make a difference.

我们使用Microsoft Visual C ++ 2008.我希望一个更一般,平台无关的答案虽然。

We're using Microsoft Visual C++ 2008. I'm kinda hoping for a more general, platform-independent answer though.

那么你认为什么?根据性能原因而不是范围原因,我们是否可以花时间更改数据类型?

So what do you think? Are we right to spend time changing our data types for performance reasons rather than range reasons?

推荐答案

我认为你有一个巨大的案例的成熟优化盯着你的脸。

I think you have a huge case of pre-mature optimization staring you in the face. Never make micro changes like this in your application until a profiler has definitively told you that it is a source of significant performance problems.

否则,您将花费大量的时间来完成这项工作。 非问题。

Otherwise you'll spend a lot of time fixing non-problems.

这篇关于在64位环境(C ++)中32位整数的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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