.NET优化的Int32 [英] .NET Optimized Int32
问题描述
尽管通读70-536培训工具包,它指出:
While reading through the 70-536 training kit, it states:
运行时优化性能 的32位整数类型(的Int32),所以 使用这些类型的柜台等 经常访问的积分 变量。
The runtime optimizes the performance of 32-bit integer types (Int32), so use those types for counters and other frequently accessed integral variables.
这是否只适用于32位环境?难道Int64的接管在64位环境中,或者是还在的Int32是更好的选择?
Does this only apply in a 32 bit environment? Does Int64 take over in a 64 bit environment, or is Int32 still the better choice?
推荐答案
这是一个有趣的方式把它。运行时不会有很多工作要做吧。 CPU被设计用于处理32位整数,这就是为什么它们是最有效的使用。
That's a funny way to put it. The runtime doesn't have much to do with it. The CPU is designed for processing 32-bit integers, which is why they're the most efficient to use.
在64位的环境中,它再次取决于CPU。然而,在x86 CPU的至少(其中,尽我所知,是.NET运行的唯一的地方),32位整数仍然是默认的。寄存器都被简单地扩大,使它们可以容纳64位的值。但是,32依然是默认的。
In a 64-bit environment, it again depends on the CPU. However, on x86 CPU's at least (which, to the best of my knowledge, is the only place .NET runs), 32-bit integers are still the default. The registers have simply been expanded so they can fit a 64-bit value. But 32 is still the default.
所以preFER 32位整数,即使是在64位模式。
So prefer 32-bit integers, even in 64-bit mode.
编辑:的违约可能是不正确的字。在CPU只是支持许多指令,定义哪些类型的数据可以处理,并且它不能。没有默认在那里。然而,一般认为在CPU被设计为有效地处理数据大小。而在x86,32位和64位模式,即32位整数。 64位值一般不贵多,但他们并意味着更长的说明。我也相信,至少64位的奔腾4是显著慢的64位老年退休金计划,尽管最近的CPU,这部分不应该是一个问题。 (但指令长度可能仍然是)
"default" is probably not the right word. The CPU just supports a number of instructions, which define which data types it can process, and which it can not. There is no "default" there. However, there is generally a data size that the CPU is designed to process efficiently. And on x86, in 32 and 64-bit mode, that is 32-bit integers. 64-bit values are generally not more expensive, but they do mean longer instructions. I also believe that at least the 64-bit capable Pentium 4's were significantly slower at 64-bit ops, although on recent CPU's, that part shouldn't be an issue. (But the instruction size may still be)
小于32位值在某种程度上更令人惊讶的。是的,有较少的数据传输,这是很好的,但CPU仍然抓住32个字节的时间。这意味着它掩盖了价值的一部分,因此这些变得更慢了。
Smaller than 32-bit values are somewhat more surprising. Yes, there is less data to transfer, which is good, but the CPU still grabs 32-byte at a time. Which means it has to mask out part of the value, so these become even slower.
这篇关于.NET优化的Int32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!