Why pointer size regardless of the type

  Size of a pointer and related hardware.

  There are a variety of data in memory, integer, floating point, character, and so on. The data storage space in memory occupied by different sizes, with the operator sizeof (Note: sizeof operators which is not a function, which play a role at compile-time) operation performed when the results are different. However, when such a different type of pointer arithmetic in the same system environment, the result is the same.

  As we all know, C language pointer describes the memory address. And this kind of thing is a memory address is addressed by the CPU. For a 4-bit CPU is concerned, it can simultaneously output data is 4 bits, i.e., 2 ^ 4 total 0000-1111 cases, it can correspond to the binary numbers to memory address location 16, i.e., CPU recognizes only out of 16 memory addresses. Even if your memory is bigger, it also shows that only 16 memory locations are available. Such principles are equally applicable to 32-bit and 64-bit CPU.

  The CPU 32 can simultaneously exhibit 32-bit data, so it is case 2 ^ 32, 2 ^ 32 corresponds to a memory location which is the maximum size of 3.85GB, so system 32 can support up to 4GB of memory. In contrast, the 64-bit CPU simultaneously handling 2 ^ 64-bit data, which obviously can correspond to 2 ^ 64 addresses of memory, while in theory, this size is converted into a decimal number is quite large, if corresponds to the memory, then a lot of memory. So we say that 64-bit systems theory supports infinite memory (infinity here is just a concept, because we can not use such a huge memory capacity).

  In summary, because the pointer is the address, so the 32-bit memory, a total of four bytes; 64-bit 64-bit address system, a total of 8 bytes - what you should get the point! Yes, 4-byte 32-bit pointer, 8-byte 64-bit pointer.

  Of course, CPU but the primary factor affecting the size of a pointer, it depends on the number of bits in addition to the operating system and compiler. The minimum size of a pointer here that decision by these three things median. For example, if the CPU, system are 64 bits, but the compiler is 32, then it is clear that only a 32-bit pointer size of 4 bytes.

 

Guess you like

Origin www.cnblogs.com/fusiji/p/11409755.html