Heap – Why Does a Heap Need to Allocate in 8-Byte Alignments?

heapword

4-bytes = word;
8-bytes = 2x word

Then why doesn't the heap just go with 4-byte alignment (because it will be grabbing a word at a time anyway, right?)

If we went with 8-byte alignments, why not 12? 16?

Best Answer

Efficiency and CPU architecture. I remember when the Alpha chips came out, they could only read memory on 32 bit boundaries. If you wanted to read byte 3, you'd load a 32-bit number then have to rotate the result to isolate the byte you want. A traditional byte-by-byte string compare was quite inefficient in this architecture.

That being said, I'm not sure what modern processors do. It's been a while since I had to deal with this.

Related Topic