why does size of the struct need to be a multiple of the largest alignment of any struct member

前端 未结 4 572
执笔经年
执笔经年 2021-01-04 11:23

I understand the padding that takes place between the members of a struct to ensure correct alignment of individual types. However, why does the data structure have to be a

4条回答
  •  天命终不由人
    2021-01-04 12:11

    Because of virtual addressing.

    "...aligning a page on a page-sized boundary lets the hardware map a virtual address to a physical address by substituting the higher bits in the address, rather than doing complex arithmetic."

    By the way, I found the Wikipedia page on this quite well written.

提交回复
热议问题