c++ - What exactly is an 'aligned pointer'? -


would please tell me aligned pointer means?

it means address being pointed @ evenly divisible factor.

sometimes term "natural alignment" used, means objects having natural alignment need placed @ addresses evenly divisble object's size.

alignment somestimes important, since many hardware-related things place restrictions on such alignment.

for instance, on classic sparc architecture (and on classical arm, think), can't read integer larger 1 byte odd address. trying halt program bus error. on x86 architecture, cpu hardware instead handles problem (by doing multiple accesses cache and/or memory needed), although might take longer. risc:ier architectures typically don't you.

things these can affect padding, i.e. insertion of dummy data between e.g. structure fields in order maintain alignment. structure this:

struct example {   char initial;   double coolness; }; 

would end having 7 bytes of padding between fields, make double field align on offset divisible own size (which i've assumed 8).

when viewed in binary, address aligned n bytes have log2(n) least-significant bits set zero. instance, object requires 32-byte alignment have properly-aligned address ends (binary) 00000, since log2(32) 5. implies address can forced alignment clearing required number of bits.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -