how to minimize padding issue with structure
Answers
Answered by
2
Explanation:
In Structure, sometimes the size of the structure is more than the size of all structures members because of structure padding. Note: But what actual size of all structure member is 13 Bytes. So here total 3 bytes are wasted. So, to avoid structure padding we can use pragma pack as well as an attribute.
Answered by
0
Minimize padding issue with structure
- Because of structure padding, the size of the structure in Structure can occasionally exceed the size of all of its members. However, the total size of the structure's members is actually 13 Bytes.
- Thus, a total of 3 bytes are wasted here. Consequently, we can employ pragma pack as well as a property to prevent structure padding.
- The compiler automatically performs structure padding to ensure that each member is byte aligned. Here, "char" is merely 1 byte, yet the number starts at the 4 byte boundary after 3 bytes of padding. It occupies 4 and 8 bytes for "int" and "double," respectively.
- One or more empty bytes (addresses) are placed (or left vacant) between memory addresses that are allocated for other structure members during memory allocation in order to align the data in memory. The phrase "structural padding" refers to this idea.
#SPJ2
Similar questions