指针的大小:制约因素 [英] Size of pointers: Dependent factors
问题描述
我在理解上的指针变量的 C
的大小取决于因素,寻找困难。我查了一些参考,我到现在为止的唯一信息是指针
的大小取决于处理器架构。我想知道以下细节
I am finding difficulties in understanding the factors on which the size of pointer variables in C
is dependent on. I checked few references, the only information I got until now is pointer
size is dependent on the processor architecture.I would like to know the following details
- 请解释更多关于如何在木构建筑的影响指针的大小。
- 在一般情况下,如果指针
x位的
然后0至2 ^(X)-1
号地址位置的应该是我.......我失去而与地址位置的数和内存的实际金额可用的程序轨道。
- Please explain more on how the architecure impacts the pointer size.
- In general, if the pointer is of
x bits
then0 to 2^(X)-1
number of address locations should be there.I am losing track while relating the number of address locations and the actual amount of memory available to the program.
推荐答案
一个指针是保存另一个内存位置的地址的变量。
A pointer is a variable that holds the address of another memory location.
现在,持有的内存引用(和最有可能的,所有其它寄存器太)将是32位长度的CPU的寄存器;这基本上什么是32位(寄存器都是32位字长的),因此指针(这是一个内存位置)意味着将一般是32位长(4字节)
Now if you are running on a 32-bit architecture, the CPU's registers that hold memory references(and most likely, all other registers too) will be of 32-bit length; that's basically what's meant by 32-bit(the registers are of 32-bit word length) and hence a pointer(which is a memory location) would usually be 32-bits long(4 bytes)
同样适用于64位CPU,因此在编译为64位CPU的C程序的指针将一般有8个字节长度(64位)
Same applies to 64-bit CPUs, and hence the pointers in a C program compiled for 64-bit CPUs will usually have 8 bytes length(64 bits)
编辑:结果
另请注意,在大多数现代架构你不真正解决您的code物理内存;您运行并解决什么叫做虚拟内存。
Please also note that in most modern architectures you don't really address physical memory with your code; you run and address what's called a Virtual Memory.
其基本概念是,你illude程序,您有充分的地址空间,为你的CPU / OS的组合。
The basic concept is that the CPU/OS combination illude your program that you have the full address space for you.
再次地址空间(该空间可以在存储器地址)长度将依赖于CPU可以多远处理地点和(在一般情况下)将取决于它的字大小。
Again, the address-space(the space you can address in memory) length will depend on how far the CPU can address locations and that (in the general case) would depend on its word-size.
这篇关于指针的大小:制约因素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!