codigo napisa³(a):
Consider the effects if your compiler didn't align a MYSTRUCT variable's
composition. Take an array of MYSTRUCT variables and the fact that the
compiler would have to index-shift over each instance in the container to
eliminate the waisted space. Then consider how the same complex index-based
addressing scheme would be required to read, write or deallocate each
instance.
Speed is far more critical than the space occupied by an instance of that
class or a container of these. Not to mention the added complexity of the
programming itself, the compiler, or the hardware re-engineering issues such
a scheme would produce.
Thank's for all replays! Now I know what's going on.
So if I want to read a bitmap file header (14 bytes) and pack in to
fallowing structure:
typedef struct _BITMAPFILEHEADER { // Offset Size
short bfType; // 0 2
long bfSize; // 2 4
short bfReserved1; // 6 2
short bfReserved2; // 8 2
long bfOffBits; // 10 4
} BITMAPFILEHEADER; // Total size: 14
....
BITMAPFILEHEADER bitmapFileHeader;
I can't just use:
fread(bitmapFileHeader,sizeof(BITMAPFILEHEADER),1,filePointer)
because data will be filled incorrectly.
Better idea will be something like that:
fread(bitmapFileHeader.bfType,sizeof(short),1,filePointer);
fread(bitmapFileHeader.bfSize,sizeof(long),1,filePointer); etc. etc.
or try to align the variables in structure.