When i was just searching for "How does free know how many bytes to free ", i came to know some facts abt dynamic memory allocation. But i need some help from u guys to clear my doubts.
1.The memory is allocated in chunks of 8 bytes , But why?
2.And i came to know that the memory manger stores the number of bytes allocated in the address right before the starting loation address of the block.
Here is the code which i found in net
The output of the above code is :
printf("%d --- %d\n",i,ch[-1]);// i -- the number of intergers, ch[-1]
// is the value of address loaction right before the starting address
// loaction of the block.
i --- ch[-1]
1 --- 17
2 --- 17
3 --- 17
4 --- 25
5 --- 25
6 --- 33
My doubt is when i allocated 1,2,3 bytes of int in ch[-1] it contains 17 and when i allocted 4,5 bytes of int in ch[-1] it contains 25 and so on.
Just i dont understand the abt output .
Plz clear my doubts.Thanks in advance.
OS -- FC3 2.6.12-prep
Machine -- 32 bit X86.