memory allocation for structures elements

前端 未结 7 1287
故里飘歌
故里飘歌 2021-01-19 05:14

Hi I am having difficulties in understanding about how the memory is allocated to the structure elements.

For example if i have the below structure and the size of c

7条回答
  •  轮回少年
    2021-01-19 06:02

    It's heavily dependent on both your processor architecture and compiler. Modern machines and compilers may choose larger or smaller padding to reduce the access cost to data.

    Four-byte alignment means that two address lines are unused. Eight, three. A chip can use that to address more memory (coarser grain) with the same amount of hardware.

    A compiler might use a similar trick for various reasons, but no compiler is required to do anything but be no less fine-grained than the processor. Often, they'll just take the biggest-size value and use it exclusively for that block. In your case, that's a double, which is eight bytes.

提交回复
热议问题