问题描述
我知道有些处理器失败,并对齐的数据,和其他人一样的哦,所以,普通的x86,也只是慢这一点。
I know that some processors fail with misaligned data, and others like the oh-so-common x86, would just be slower with that.
我的问题是为什么呢?为什么一个x86处理器很难从指针获取数据 0x12345679
比它从指针为0x12345678
?只是要清楚,我知道如果数据是多页的页面错误可能发生,而据我所知,更多的数据可能需要从内存中获取(一个部件的值的开始和一个用于结束) ,但事实并非总是如此,这是不是我的问题是什么。我问,为什么总是慢?
My question is why? Why is it harder for an x86 processor to get the data from the pointer 0x12345679
than it is from the pointer 0x12345678
? Just to be clear, I'm aware that page faults may happen if the data is in multiple pages, and I understand that more data may need to be fetched from memory (one part for the start of the value and one for the end), but that isn't always true and this isn't what my question is about. I'm asking, why is it always slower?
假如记忆开始于 0x10000000处
。为什么更难处理器获得一个2字节短
从 0x10000001
比为 0x10000002
?为什么很难得到一个4字节 INT
从 0x10000001
比为 0x10000000处
?等等。
Suppose the memory starts at 0x10000000
. Why is it harder for the processor to get a 2-byte short
from 0x10000001
than it is from 0x10000002
? Why is it harder to get a 4-byte int
from 0x10000001
than it is from 0x10000000
? And so forth.
推荐答案
该处理器只能访问内存中的对齐方式。这是的结果如何,处理器和存储器功能之间的互连。
The processor can only access memory in an aligned fashion. This is a consequence of how the interconnect between the processor and memory functions.
在一个处理器支持不对齐的读取,究竟发生了什么是处理器发出两个独立的读取(或更大尺寸的一个读)和缝合部分组合在一起,这就是为什么它是不是一致的读取速度较慢。
When a processor supports unaligned reads, what's really happening is the processor issuing two separate reads (or one read of larger size) and stitching the parts together, which is why it's slower than an aligned read.
这篇关于为什么对齐项重要的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!