32位处理器能够真正解决2 ^ 32的内存位置? [英] Can a 32-bit processor really address 2^32 memory locations?

查看:133
本文介绍了32位处理器能够真正解决2 ^ 32的内存位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这可能是一个奇怪的/愚蠢的问题,但在这里不用...

在这个问题是NULL在C语言所需/定义为零?中,已经建立的指针指向的不可寻址存储器位置,并且还认为 0

现在,据说一个32位处理器可以寻址 2 ^ 32 存储位置。

2 ^ 32 是不同的编号,可以重复$ P $使用 32 位psented只数。在这些数字是 0 。但是,由于 0 ,即 NULL ,则应该指向什么都没有,我们不应该说32比特处理器只能处理 2 ^ 32 - 1 存储单元(因为 0 不应该是一个有效的地址)?


解决方案

  

NULL指针指向一个不可寻址存储器位置


这是不正确的。从问题中接受的答案您链接:


  

注意,因为如何空指针的规则制定,您使用值来分配/比较空指针保证是零,但实际上存储在里面的指针的位模式可以是任何其他东西。


其中,我知道你其实通过标记的地址空间的前几页为无效处理这个大多数平台。这并不意味着处理器无法应对这样的事情;它使低值非有效的指针只是一种方便的方式。例如,几个Windows API使用这个资源ID和一个指向实际数据来区分;一切都低于一定数值(65K如果我没有记错)不是一个有效的指针,而是一个有效的资源ID。

最后,只是因为C说,一些并不意味着CPU需要的方式加以限制。当然,C说访问空模式是不确定的 - 但有一个人在写作组装没有任何理由需要受到这样的限制。实机通常可以做更多的事情比C标准说,他们不得不这样做。虚拟内存,SIMD指令和硬件IO是一些简单的例子。

I feel this might be a weird/stupid question, but here goes...

In the question Is NULL in C required/defined to be zero?, it has been established that the NULL pointer points to an unaddressable memory location, and also that NULL is 0.

Now, supposedly a 32-bit processor can address 2^32 memory locations.

2^32 is only the number of distinct numbers that can be represented using 32 bits. Among those numbers is 0. But since 0, that is, NULL, is supposed to point to nothing, shouldn't we say that a 32-bit processor can only address 2^32 - 1 memory locations (because the 0 is not supposed to be a valid address)?

解决方案

the NULL pointer points to an unaddressable memory location

This is not true. From the accepted answer in the question you linked:

Notice that, because of how the rules for null pointers are formulated, the value you use to assign/compare null pointers is guaranteed to be zero, but the bit pattern actually stored inside the pointer can be any other thing

Most platforms of which I am aware do in fact handle this by marking the first few pages of address space as invalid. That doesn't mean the processor can't address such things; it's just a convenient way of making low values a non valid pointer. For instance, several Windows APIs use this to distinguish between a resource ID and a pointer to actual data; everything below a certain value (65k if I recall correctly) is not a valid pointer, but is a valid resource ID.

Finally, just because C says something doesn't mean that the CPU needs to be restricted that way. Sure, C says accessing the null pattern is undefined -- but there's no reason someone writing in assembly need be subject to such limitations. Real machines typically can do much more than the C standard says they have to. Virtual memory, SIMD instructions, and hardware IO are some simple examples.

这篇关于32位处理器能够真正解决2 ^ 32的内存位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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