struct

Andrew Haley aph@redhat.com
Mon Oct 1 08:20:00 GMT 2018


On 09/30/2018 06:44 PM, sundaresh wrote:
> Why do struct's take up a lot more memory than the sum of the sizes of its
> members ? This increases by even a lot more the larger the struct gets . If
> the compiler is doing padding or aligning I would like to disable and not
> have that at all since it is unnecessarily wasteful of memory ? I
> encountered a similar problem when declaring floating point variables
> independently outside a struct. The problem becomes worse if these floating
> point variables are struct members.

Alignment, usually. But it's worth noting that GCC follows the system
ABI specfication for laying out structures in memory. We usually don't
get to decide how it's done.

-- 
Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671



More information about the Gcc-help mailing list