Вопрос

I am attempting to learn about memory alignment, without much success admittedly. I am using this article from IBM.

Can someone please explain to me what this excerpt means from the double byte memory access granularity section:

However, notice what happens when reading from address 1. Because the address doesn't fall evenly on the processor's memory access boundary, the processor has extra work to do. Such an address is known as an unaligned address. Because address 1 is unaligned, a processor with two-byte granularity must perform an extra memory access, slowing down the operation.

Why is another memory access in order? What does it mean by memory access boundary and it being even on the memory access boundary?

I have a VERY limited knowledge on the CPU, as I have only delt with upper level programming (Objective-C and C++). Any help is greatly appreciated!

Thanks!

Это было полезно?

Решение

The example is describing what happens when you try to read a block of 4 consecutive bytes on a CPU with double-byte access granuality. On this type of CPU, memory is accessed as pairs of bytes, always starting with an even-numbered byte.

If you try to read the block starting with byte 0, it has to perform 2 reads: bytes 0-1 and bytes 2-3.

If you try to read the block starting with byte 1, it has to perform 3 reads: bytes 0-1 (to get byte 1), bytes 2-3, and bytes 4-5 (to get byte 4).

Memory access granularity is the number of bytes it accesses at a time, and a memory access boundary is where each of these groups of bytes begins. The groups of bytes are always addressed at even multiples of the granularity -- if it's double-byte granularity they start on even addresses, if it's quad-byte granularity they're at multiples of 4.

As an analogy, consider an apartment building with 4 units on each floor. Units 0-3 are on floor 0, units 4-7 are on floor 1, etc. If you want to slip a flyer under the doors of units 0-3, you only have to go to one floor. But if you want to slip a flyer under 1-4, you have to go to 2 floors: floor 0 for 1-3, floor 2 for unit 4.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top