I know that malloc() takes its memory chunks from the heap. assuming that there are two consecutive malloc calls, one immedietly after the other, one would assume that the chunks would be allocated nearby like blocks in an array,
what i mean is
char * p1 = (char*)malloc(sizeof(char)); //now let p1 =1460 (address)
char * p2 = (char*)malloc(sizeof(char));
now p2 should be =1461 (or atleast 1462 for even address boundary), right? but instead, my Turbo Compiler gives the allocated address as 1468 (i.e. an 8 byte gap between the addresses consecutive calls).
experimenting a lot, there always seems to be either a 4 byte or 8 byte gap between the consecutively malloc()'d allocated addresses. , so if we allocated a 3 int array using malloc(3*sizeof(int)), and then one more malloc, the first malloc ()returned address would be 1460, and the second malloc will return 1468.
I searched in the net and found out that ANSI doesnt specify how the memory must be allocated between malloc calls, it is specific to single malloc calls.
could anyone tell me why there is a gap, ?? I do hope u got my doubt....