为什么任何数据类型的大小都取决于机器? [英] why does size of any data type depend on the machine?

查看:51
本文介绍了为什么任何数据类型的大小都取决于机器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道这取决于机器或编译器..但为什么以及如何?

we know it depends on machine or compiler..but why and how?

推荐答案

对于初学者来说,机器的架构,比如 16 位或 64 位,将决定地址总线的宽度,并有效地决定您可以访问多少内存无需借助虚拟内存之类的技巧.

For starters, the machine's architecture, say 16 bit or 64 bits, will determine how wide the address bus is, and that effectively determines how much memory you can access without resorting to tricks like virtual memory.

通常,CPU 内部的硬件寄存器与架构的其余部分具有相同的位宽;因此,在 32 位 CPU 上,以 32 位块加载和存储数据通常是最有效的.在某些环境中,甚至有必要将所有数据对齐在 32 位边界上,即无法从字节地址不能被 4 整除的内存地址中获取数据.

Usually, the hardware registers inside the CPU will have the same bit width as most of the rest of the architecture; so on a 32 bit CPU it will usually be most efficient to load and store data in 32 bit chunks. In some environments, it's even necessary that all your data be aligned on 32 bit boundaries, i.e. you can't grab data from a memory address whose byte address is not divisible by 4.

在软件中绕过所有这些限制是可能的,但对于最高效的程序,您会希望编译器的数据类型与系统硬件的数据类型密切相关.

It's possible to circumvent all these restrictions in software, but for the most efficient programs, you will want your compiler's data types to be closely related to the system hardware's.

这篇关于为什么任何数据类型的大小都取决于机器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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