为什么 32 位和 64 位地址有两种不同的长度?
Why there are two different lengths for addresses in 32 and 64 bit?
当我在 64 位机器上 运行 这段代码时 :
#include <stdio.h>
int main()
{
int a[10];
printf("%p",&a);
return 0;
}
它输出:
0x7fffe9ebf984 (14 digits)
我在教科书中找到了这个:
My computer's memory address is 32 bit and is represent in eight
hexadecimal digits.
我的问题是:
为什么 32 位和 64 位的地址有两种不同的长度?
32位的地址是8位,64位的地址是14位是怎么表示的?
那个内存地址有12个数字,不是14个。每个数字是一个4位的字。 12*4 = 48,这是一个 256 TB 的地址 space。当前 CPU 仅使用完整 64 位地址 space 的低 48 位,因为这允许构建更便宜的晶体管(我们不会在不久的将来完全使用我们可以从 64 位使用的内存未来)。当我们达到 48 位限制时,制造商可能会创建真正使用 64 位完整地址 space 的 CPU,但现在没有必要。
您拥有 32 位和 64 位地址的原因必须处理 CPU 体系结构。较旧的 CPU 使用 32 位,但使用 32 位地址会将您限制为 4GB 的系统内存。这就是更改为 64 位地址的原因。系统可以支持更多地址,因此可以支持更多 RAM。
您号码中的“0x”只是告诉您它是十六进制的。所以它实际上是 12 位数字,其中每个数字是 4 位(总共 48 位)。
First things first: 0x
前缀表示后面是hexadecimal (base 16) number. The hexadecimal system extends the set of digits in the decimal system (0 through 9) with a, b, c, d, e and f that stand for the decimal numbers 10, 11, 12, 13, 14 and 15, respectively. The reason that we prefer hexadecimal numbers to decimal ones (at least on a machine whose word length是四的倍数)是每个十六进制数字方便对应一组4位(二进制数字) .例如:
Hexadecimal: 3
Binary: 0 0 1 1
--------------------
Hexadecimal: F
Binary: 1 1 1 1
通常当我们说机器是“32 位”或“64 位”时,我们谈论的是 virtual address 长度——即构成内存地址的位数用户态进程的视角。 (这通常但不一定与字长一致。)
在 x86-32 机器上,例如旧的 Pentium,虚拟地址大小为 32 位。这意味着可以使用八个十六进制数字写入地址。例如,0x80000000
表示 2 GiB 标记。虚拟地址是 32 位的事实意味着任何给定进程只能直接引用 4 GiB 内存(实际上,可用内存量甚至更少!)。
对于当今的许多应用程序,例如大型 in-memory databases, 4 GiB of virtual memory is too small to hold the data set. This prompted the introduction of 64-bit machines, such as those based on the x86-64 architecture. In theory, a 64-bit machine should be able to address 16 EiB. But, as others have noted, the x86-64 architecture currently limits the virtual address size to 48 bits by requiring them to be in a canonical form。
顺便说一句,规范地址space下半部分的地址可以用12个十六进制数字来写。像往常一样,我们在打印时省略前导零。
我们不太可能在短期内看到从 32 位到 64 位计算的完全转变,如果有的话。仍然有许多应用程序,特别是在嵌入式系统中,根本不需要 64 位地址支持的内存量;事实上,16 位甚至 8 位微控制器仍然非常普遍。
当我在 64 位机器上 运行 这段代码时 :
#include <stdio.h>
int main()
{
int a[10];
printf("%p",&a);
return 0;
}
它输出:
0x7fffe9ebf984 (14 digits)
我在教科书中找到了这个:
My computer's memory address is 32 bit and is represent in eight hexadecimal digits.
我的问题是:
为什么 32 位和 64 位的地址有两种不同的长度?
32位的地址是8位,64位的地址是14位是怎么表示的?
那个内存地址有12个数字,不是14个。每个数字是一个4位的字。 12*4 = 48,这是一个 256 TB 的地址 space。当前 CPU 仅使用完整 64 位地址 space 的低 48 位,因为这允许构建更便宜的晶体管(我们不会在不久的将来完全使用我们可以从 64 位使用的内存未来)。当我们达到 48 位限制时,制造商可能会创建真正使用 64 位完整地址 space 的 CPU,但现在没有必要。
您拥有 32 位和 64 位地址的原因必须处理 CPU 体系结构。较旧的 CPU 使用 32 位,但使用 32 位地址会将您限制为 4GB 的系统内存。这就是更改为 64 位地址的原因。系统可以支持更多地址,因此可以支持更多 RAM。
您号码中的“0x”只是告诉您它是十六进制的。所以它实际上是 12 位数字,其中每个数字是 4 位(总共 48 位)。
First things first: 0x
前缀表示后面是hexadecimal (base 16) number. The hexadecimal system extends the set of digits in the decimal system (0 through 9) with a, b, c, d, e and f that stand for the decimal numbers 10, 11, 12, 13, 14 and 15, respectively. The reason that we prefer hexadecimal numbers to decimal ones (at least on a machine whose word length是四的倍数)是每个十六进制数字方便对应一组4位(二进制数字) .例如:
Hexadecimal: 3
Binary: 0 0 1 1
--------------------
Hexadecimal: F
Binary: 1 1 1 1
通常当我们说机器是“32 位”或“64 位”时,我们谈论的是 virtual address 长度——即构成内存地址的位数用户态进程的视角。 (这通常但不一定与字长一致。)
在 x86-32 机器上,例如旧的 Pentium,虚拟地址大小为 32 位。这意味着可以使用八个十六进制数字写入地址。例如,0x80000000
表示 2 GiB 标记。虚拟地址是 32 位的事实意味着任何给定进程只能直接引用 4 GiB 内存(实际上,可用内存量甚至更少!)。
对于当今的许多应用程序,例如大型 in-memory databases, 4 GiB of virtual memory is too small to hold the data set. This prompted the introduction of 64-bit machines, such as those based on the x86-64 architecture. In theory, a 64-bit machine should be able to address 16 EiB. But, as others have noted, the x86-64 architecture currently limits the virtual address size to 48 bits by requiring them to be in a canonical form。
顺便说一句,规范地址space下半部分的地址可以用12个十六进制数字来写。像往常一样,我们在打印时省略前导零。
我们不太可能在短期内看到从 32 位到 64 位计算的完全转变,如果有的话。仍然有许多应用程序,特别是在嵌入式系统中,根本不需要 64 位地址支持的内存量;事实上,16 位甚至 8 位微控制器仍然非常普遍。