R
ramu
Hi all,
I understand that some compilers pad some bytes to the
aggregate data types in order to access the members of the aggregate
data types(i.e. structure) fast. This depends on the architectures.
Some architectures cannot access the data which will be stored on the
odd addresses or they may find difficult to access it. This is the
reason for padding extra bytes.
Now consider the following structure:
struct {
int i; // 4 bytes
char c; // 1 byte
char b; // 1 byte
}a;
Now consider the memory representation for this structure:
----------------------------- Memory locations
i 0
-----------------------------
i 1
-----------------------------
i 2
------------------------------
i 3
-------------------------------
c 4
--------------------------------
b 5
--------------------------------
padding 6
---------------------------------
padding 7
---------------------------------
The size of this strucutre will be 8bytes after padding.
The first 4 memory locations(0 to 3) are allocated for int i;
The next byte(4) is allocated for char c;
the next byte(5) is allocated for char b;
Now my doubt is , does not the processor find it difficult to access
the value of the variable which is stored in odd memory location(ie.
5)? can anyone elaborate on this?
Regards
I understand that some compilers pad some bytes to the
aggregate data types in order to access the members of the aggregate
data types(i.e. structure) fast. This depends on the architectures.
Some architectures cannot access the data which will be stored on the
odd addresses or they may find difficult to access it. This is the
reason for padding extra bytes.
Now consider the following structure:
struct {
int i; // 4 bytes
char c; // 1 byte
char b; // 1 byte
}a;
Now consider the memory representation for this structure:
----------------------------- Memory locations
i 0
-----------------------------
i 1
-----------------------------
i 2
------------------------------
i 3
-------------------------------
c 4
--------------------------------
b 5
--------------------------------
padding 6
---------------------------------
padding 7
---------------------------------
The size of this strucutre will be 8bytes after padding.
The first 4 memory locations(0 to 3) are allocated for int i;
The next byte(4) is allocated for char c;
the next byte(5) is allocated for char b;
Now my doubt is , does not the processor find it difficult to access
the value of the variable which is stored in odd memory location(ie.
5)? can anyone elaborate on this?
Regards