03
Nov
C Structure Padding
Related Blog Items
- Structure padding
- Structure padding explained
- Unnamed Bit-Field
- C++ Advanced Tutorial - Lesson 5
- C++ Basics Tutorial - Lesson 3
-
to access a structure member fastly, structure need to be padded
-
Padding will be done for each and every member, if required, not for the entire structure
-
Alignment : data storing boundary address starts at aligned address
Examples:
Size of int = 4 bytes
size of char = 1byte
alignment 64 bit (4 bytes)
Struct
{
int a ;
char b ;
} ;
size of struct = 8
Struct
{
int a ;
char b ;
int c ;
short int d ;
char e ;
} ;
size of struct = 16
|
+—————————-+
| a | b(3) | c | d e (1)|
+—————————-+
() padded bytes
|
Is there any way to supress this padding ?
Yes, using pragmas , typically pragma look like this
#pragma pack(1)
Why padding ?
For faster access to the members.
Popularity: 14%
You need to log on to convert this article into PDF
Related Blog Items - Structure padding
- Structure padding explained
- Unnamed Bit-Field
- C++ Advanced Tutorial - Lesson 5
- C++ Basics Tutorial - Lesson 3
Related Blog Items
- Structure padding
- Structure padding explained
- Unnamed Bit-Field
- C++ Advanced Tutorial - Lesson 5
- C++ Basics Tutorial - Lesson 3
A very good article. Helped me very much to understand padding.
May 30th, 2008 at 11:59 am
Very useful tutorial
May 30th, 2008 at 12:27 pm