I just learnt about 4 or 8 memory alignment and came about this question.
Will Memory alignment happen in virtual memory space or absolute addresss?
I guess the answer is virtual memory spaceļ¼ and the os will load the process to the position that the absolute address ends with ‘0X00’ or ‘0X0’.
If not, please show me why. Thanks a lot. XD
Advertisement
Answer
Both virtual and actual addresses will be word-aligned to the CPU’s native word-size where appropriate(*). (The reason for that is that the virtual-to-physical mapping is done on a per-page basis, and the size of a memory page is always an even multiple of the CPU’s native word-size).
(*) the exception would be for items that are smaller than a word, and are packed together consecutively to save memory; e.g. many of the individual elements inside of char
and uint_8
arrays will necessarily not be word-aligned.