Knowing how the underlying hardware works helps explain a concept that programmers
encounter: byte alignment. We say that an integer value is aligned if the
bytes of the integer correspond to a word in the underlying physical memory. In Figure
10.7, for example, an integer composed of bytes 12, 13, 14, and 15 is aligned, but an integer
composed of bytes 6, 7, 8, and 9 is not.
On some architectures, byte alignment is required — the processor raises an error
if a program attempts an integer access using an unaligned address. On other processors,
arbitrary alignment is allowed, but unaligned accesses result in lower performance
than aligned accesses. We can now understand why an unaligned address requires more
accesses of physical memory: the memory controller must convert each processor request
into operations on the underlying memory. If an integer spans two words, the
controller must perform two read operations to obtain the requested bytes. Thus, even
if the processor permits unaligned access, programmers are strongly encouraged to align
data values.
We can summarize:
The organization of physical memory affects programming: even if a
processor allows unaligned memory access, aligning data on boundaries
that correspond to the physical word size can improve program
performance.
Results (
Thai) 3:
[Copy]Copied!
รู้จักฮาร์ดแวร์พื้นฐานงานช่วยอธิบายแนวคิดที่โปรแกรมเมอร์
พบ : แนวไบต์ เรากล่าวว่าจำนวนเต็มค่าสอดคล้องถ้า
ไบต์ของจำนวนเต็มที่สอดคล้องกับคำพื้นฐานทางกายภาพหน่วยความจำ ในรูป
10.7 , ตัวอย่างเช่น , จำนวนเต็ม จำนวนไบต์ที่ 12 , 13 , 14 และ 15 สอดคล้อง แต่จำนวนเต็ม
จำนวนไบต์ที่ 6 , 7 , 8 และ 9
.บนสถาปัตยกรรมแนวไบต์เป็นสิ่งจำเป็น - หน่วยประมวลผลหัสข้อผิดพลาด
ถ้าโปรแกรมพยายามเข้าถึงการใช้จำนวนเต็มที่อยู่ unaligned . บนโปรเซสเซอร์อื่น ๆ ,
พลจัดได้ แต่ unaligned เข้าถึงผลการปฏิบัติงานต่ำกว่า
ชิดเข้า . ตอนนี้เราสามารถเข้าใจเหตุผลที่อยู่ unaligned ต้องการมากกว่า
เข้าถึงหน่วยความจำกายภาพ :หน่วยความจำควบคุมต้องแปลงแต่ละประมวลผลการร้องขอ
ในการดําเนินงานบนพื้นฐานของหน่วยความจำ ถ้าจำนวนเต็มครอบคลุมสองคำ ผู้ควบคุมต้องดำเนินการสองอ่าน
ปฏิบัติการได้รับร้องขอไบต์ ดังนั้น แม้
ถ้าตัวประมวลผลใบอนุญาตการเข้าถึง unaligned โปรแกรมเมอร์จะขอสนับสนุนให้มีการจัดข้อมูลค่า
.
เราสามารถสรุป :
องค์กรของหน่วยความจำกายภาพที่มีผลต่อโปรแกรม :แม้ว่า
โปรเซสเซอร์ช่วยให้เข้าถึงหน่วยความจำ unaligned สอดคล้องกับข้อมูลบนขอบเขต
ที่สอดคล้องกับคำทางกายภาพขนาดสามารถปรับปรุงประสิทธิภาพของโปรแกรม
Being translated, please wait..
![](//wwwimg.ilovetranslation.com/pic/loading_3.gif?v=b9814dd30c1d7c59_8619)