Memory Alignment

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
User avatar
~
Member
Member
Posts: 1226
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Memory Alignment

Post by ~ »

I have read in some places that the memory must be aligned according to its size, and so they don't impact performance:

Arbitrary-size structures: 16-byte boundary (if used with SIMD instructions)
Single bytes: Anywhere
WORDs: Word-aligned
DWORDs: DWORD-aligned
QWORDs: QWORD-aligned
Code: Aligned to 2-byte (RM), 4-byte (PM) or 8-byte (64bit)


If so, it seems more comfortable, less space-wasting and an addition to the simple recommendation of always align to platform register-width.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: Memory Alignment

Post by Candy »

~ wrote:I have read in some places that the memory must be aligned according to its size, and so they don't impact performance:

Arbitrary-size structures: 16-byte boundary (if used with SIMD instructions)
Single bytes: Anywhere
WORDs: Word-aligned
DWORDs: DWORD-aligned
QWORDs: QWORD-aligned
Code: Aligned to 2-byte (RM), 4-byte (PM) or 8-byte (64bit)


If so, it seems more comfortable, less space-wasting and an addition to the simple recommendation of always align to platform register-width.
For higher performance (in some cases !) use cache line alignment for some bits of code.
Post Reply