What is the pointer size?

Source: Internet
Author: User

Who determines the pointer size? What is it?
It should be said that this is a very basic problem. in textbooks, the pointer size is the same as the machine Character length, that is, the 32-bit pointer length is 4 bytes! But right? Why?

I searched for relevant information... I found that the answers were not uniform, and many people were also confused.

Next we will make a systematic arrangement and analysis for this problem:

First, I will introduce several basic concepts: (mainly from Baidu encyclopedia)

Word Length: the number of digits that process the binary number at the same time is called the word length. Generally, the 8-bit CPU that processes 8-bit data is called an 8-bit CPU, and a 32-bit CPU is a 32-bit binary data processed at the same time. Each 0 or 1 of a binary is the smallest unit of binary. It is called a bit ).

Generally, a group of binary numbers processed by a computer within the same time is called a computer's "Word", and the number of digits of these binary numbers is "Word Length ". The word length is closely related to the functions and usage of computers and is an important technical indicator of computers. The word length directly reflects the computing precision of a computer. To meet different requirements and coordinate the relationship between the computing precision and the hardware cost, most computers support variable-length computing, that is, the semi-font length, full-character length (or single-word length), and double-character length operations can be implemented in the machine. When other indicators are the same, the larger the word length, the faster the computer processes data. In the early days, the word length of a microcomputer was generally 8-bit or 16-bit, and the processor of 386 or higher was mostly 32-bit. Currently, most of the computers on the market have 64-bit processors.

The word length is determined by the number of data bus entries in the external data path of the microprocessor (CPU.

Minimum addressable unit: the minimum addressable unit of memory is usually byte. That is to say, a pointer address value can correspond to a byte space in the memory.

Addressing space: addressing space generally refers to the CPU's ability to address memory. The maximum range of addresses that the CPU can search for is called addressing capability. The addressing capability of the CPU is measured in bytes (bytes are the smallest addressable unit ), for example, a 32-bit addressing CPU can address a 32-bit address to the power of 4 GB, which is why a 32-bit addressing CPU can be used with up to 4 GB memory, if there is more, the CPU cannot be found.

Here, the addressing bits of the CPU are determined by the number of bits of the address bus. The addressing bits of the 32-bit CPU are not necessarily 32 bits, because the 32-bit CPU indicates the word length.

Explanation for addressing Range Calculation: for 32-bit addressing CPUs, the address value is a 32-bit binary number, so the maximum address can be expressed as the power of 32 (4G, the maximum memory space is 4 GB, where G represents the quantity and GB represents the capacity ). At the same time, we can easily see that the value of a pointer is a 32-bit binary number, and 32-bit corresponds to 4 bytes (bytes ). Therefore, the pointer size is actually determined by the number of addresses of the CPU, rather than the word length.

 

Analyze the following situations:

32-bit compiler of 32-bit operating system on 32-bit processor, pointer size 4 bytes.
32-bit operating system 16-bit compiler on 32-bit processor, pointer size 2 bytes.
The 16-bit compiler of the 16-bit operating system on a 32-bit processor. the pointer size is 2 bytes.
The 16-bit compiler of the 16-bit operating system on a 16-bit processor. the pointer size is 2 bytes.

The result shows that the pointer size is related to the compiler ??

This is not the case. In the preceding cases, the addressing bits in the current operating mode of the processor are different, as shown below:

Intel 32-bit processor 32-bit operating mode, logic addressing 32 bits, pointer is 32 bits, that is, 4 bytes
Intel 32-bit processor 16-bit virtual machine running mode, logic addressing bits 16, pointer is 16 bits, that is, 2 bytes

The purpose of the compiler is to convert the sourceProgramCompile the target file to run on the hardware. If a compiler supports a 32-bit CPU, it can compile the source program into a target file that can run on the CPU. The pointer size in the source program will also be compiled by the compiler to select 4 bytes based on the number of addresses of the CPU (such as 32-bit.

 

In summary, the pointer size is determined by the number of addresses in the current CPU running mode!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.