K 8 due to double member c p10 3 bytes i0 p14 i1 4

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Address must be mulNple of K   Aligned data is required on some machines; it is advised on IA32   Treated differently by IA32 Linux, x86 ­64 Linux, and Windows!   MoMvaMon for Aligning Data   Physical memory is accessed by aligned chunks of 4 or 8 bytes (system ­ dependent)   Inefficient to load or store datum that spans quad word boundaries   Also, virtual memory is very tricky when datum spans two pages (later…)   Compiler   Inserts padding in structure to ensure correct alignment of fields   sizeof() should be used to get true size of structs Structures and Alignment University of Washington Specific Cases of Alignment (IA32)   1 byte: char, …   no restricNons on address   2 bytes: short, …   lowest 1 bit of address must be 02   4 bytes: int, float, char *, …   lowest 2 bits of address must be 002   8 bytes: double, …   Windows (and most other OSs & instrucNon sets): lowest 3 bits 0002   Linux: lowest 2 bits of address must be 002     i.e., treated the same as a 4 ­byte primiNve data type 12 bytes: long double   Windows, Linux: lowest 2 bits of address must be 002 Structures and Alignment University of Washington SaMsfying Alignment with Structures     struct S1 { char c;   Must saNsfy every member’s alignment requirement int i[2]; double v; Overall structure placement } *p1; Within structure:   Each structure has alignment requirement K K = Largest alignment of any element   IniNal address & structure length must be...
View Full Document

This document was uploaded on 04/04/2014.

Ask a homework question - tutors are online