16 位整数 vs 32 位整数 vs 64 位整数 [英] 16 bit Int vs 32 bit Int vs 64 bit Int

查看:40
本文介绍了16 位整数 vs 32 位整数 vs 64 位整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我从未接受过计算机科学的正规"教育(我在高中),所以我一直想知道这个问题,所以请原谅我对这个主题的无知.

I've been wondering this for a long time since I've never had "formal" education on computer science (I'm in highschool), so please excuse my ignorance on the subject.

在支持标题中列出的三种整数类型的平台上,哪个更好,为什么?(我知道每种类型的 int 在内存中都有不同的长度,但我不确定这意味着什么或它如何影响性能,或者从开发人员的角度来看,哪个比另一个更有优势).

On a platform that supports the three types of integers listed in the title, which one's better and why? (I know that every kind of int has a different length in memory, but I'm not sure what that means or how it affects performance or, from a developer's view point, which one has more advantages over the other).

预先感谢您的帮助.

推荐答案

更好"是一个主观术语,但某些整数在某些平台上的性能更高.

"Better" is a subjective term, but some integers are more performant on certain platforms.

例如,在 32 位计算机(由 32 位平台和 Win32 等术语引用)中,CPU 被优化为一次处理 32 位值,而 32 指的是CPU 可以在一个周期内消耗或产生.(这是一个非常简单的解释,但它传达了总体思路).

For example, in a 32-bit computer (referenced by terms like 32-bit platform and Win32) the CPU is optimized to handle a 32-bit value at a time, and the 32 refers to the number of bits that the CPU can consume or produce in a single cycle. (This is a really simplistic explanation, but it gets the general idea across).

在 64 位计算机中(最新的 AMD 和 Intel 处理器属于此类),CPU 被优化为一次处理 64 位值.

In a 64-bit computer (most recent AMD and Intel processors fall into this category), the CPU is optimized to handle 64-bit values at a time.

因此,在 32 位平台上,加载到 32 位地址中的 16 位整数需要将 16 位清零,以便 CPU 可以对其进行操作;一个 32 位整数将立即可用而无需任何更改,并且一个 64 位整数需要在两个或多个 CPU 周期内操作(一次用于低 32 位,然后再次用于高 32 位).

So, on a 32-bit platform, a 16-bit integer loaded into a 32-bit address would need to have 16 bits zeroed out so that the CPU could operate on it; a 32-bit integer would be immediately usable without any alteration, and a 64-bit integer would need to be operated on in two or more CPU cycles (once for the low 32-bits, and then again for the high 32-bits).

相反,在 64 位平台上,16 位整数需要将 48 位清零,32 位整数需要将 32 位清零,并且可以立即对 64 位整数进行运算.

Conversely, on a 64-bit platform, 16-bit integers would need to have 48 bits zeroed, 32-bit integers would need to have 32 bits zeroed, and 64-bit integers could be operated on immediately.

每个平台和 CPU 都有一个本机"位(例如 32 或 64),这通常会限制该 C​​PU 可以访问的其他一些资源(例如,3GB/4GB 内存限制为 32-位处理器).80386 处理器系列(以及后来的 x86)处理器使 32 位成为常态,但现在像 AMD 和英特尔这样的公司目前正在使 64 位成为常态.

Each platform and CPU has a 'native' bit-ness (like 32 or 64), and this usually limits some of the other resources that can be accessed by that CPU (for example, the 3GB/4GB memory limitation of 32-bit processors). The 80386 processor family (and later x86) processors made 32-bit the norm, but now companies like AMD and then Intel are currently making 64-bit the norm.

这篇关于16 位整数 vs 32 位整数 vs 64 位整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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