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?
|
|
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. |
|||||||
|
|
Short answer is "It doesn't". The alignment is associated with the implementation details of the heap manager, nothing more. Your heap manager may have an alignment requirement for various reasons, such as efficiency, architecture, whim of the writer or what ever. If you have a reason to care, please share it with us. BTW:
This is an assumption, is incorrect, and has lead to many varied, sometimes expensive and always inexcusable software porting problems. The size of a word depends on the hardware architecture, OS, language and compiler being used. |
|||||||||||
|