hi,
can u pls tell me abt structure padding and the memory pools.how to find out memory leaks.
can u pls tell me abt structure padding and the memory pools.how to find out memory leaks.
struct MyStructA {
char a;
char b;
int c;
};
struct MyStructB {
char a;
int c;
char b;
};
int main(void) {
int sizeA = sizeof(struct MyStructA);
int sizeB = sizeof(struct MyStructB);
printf("A = %d\n", sizeA);
printf("B = %d\n", sizeB);
return 0;
}
tyreld@susie:~/Desktop> ./a.out A = 8 B = 12
#include<stdio.h>
#pragma pack(push)
#pragma pack(1)
struct test{
char a;//1 byte //Genrally padded so that int can start from 4 byte alignment
int b;//
char c;//1 byte //generally padded so that d can start in 2 byte allignment
short d;
};
#pragma pack(pop)
typedef struct test testStructure;
int main()
{
testStructure testData;
testStructure testDataArray[4];
int iterator;
printf("\n Address of test Data is 0x %x \n", &testData);
printf(" Address of char a in testData is 0x %x \n", &(testData.a));
printf(" Address of int b in testData is 0x %x \n", &(testData.b));
printf(" Address of char c in testData is 0x %x \n", &(testData.c));
printf(" Address of short d in testData is 0x %x \n", &(testData.d));
printf(" size of struct test is %d\n", sizeof(struct test));
printf("\n Printing the address in Array\n");
for(iterator = 0; iterator < 4; iterator ++)
{
printf("Iterator value is %d \n", iterator);
printf("\n Address of testDataArray is 0x %x \n", &testDataArray[iterator]);
printf(" Address of char a in testDataArray is 0x %x \n", &(testDataArray[iterator].a));
printf(" Address of int b in testDataArray is 0x %x \n", &(testDataArray[iterator].b));
printf(" Address of char c in testDataArray is 0x %x \n", &(testDataArray[iterator].c));
printf(" Address of short d in testDataArray is 0x %x \n", &(testDataArray[iterator].d));
}
return 0;
}
#pragma pack(1)
struct test{
char a;//1 byte //Genrally padded so that int can start from 4 byte alignment
int b;//
char c;//1 byte //generally padded so that d can start in 2 byte allignment
short d;
};
Comment