From mboxrd@z Thu Jan 1 00:00:00 1970 From: ishubist@gmail.com (Abhishek Bist) Date: Thu, 23 Apr 2015 11:23:56 +0530 Subject: Basic question about malloc Message-ID: <20150423055356.GA9678@localhost.localdomain> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On Thu, 23 Apr 2015 09:52:56 +0800, ????????? said : I'm looking for that whether the object allocated by malloc is the multiple of certain bytes! Or how does the malloc allocate dynamic memory ?? I does an experiment in my computer! #include #include #define NUM 33 int main(int argc,const char *argv[]) { char *a, *b, *c; a = malloc(NUM); b = malloc(NUM); c = malloc(NUM); printf("a = %x\n",a); printf("b = %x\n",b); printf("c = %x\n",c); free(a); free(b); free(c); return 0; } But the result has no feature about a ,b ,c! Can someone tell me what's wrong with me? My GCC version is gcc (Debian 4.9.2-10) 4.9.2 mudongliang Hey, ASFAIK you are looking for the number of bytes allocated to you after calling malloc.First of all malloc is not a function of a kernel space. The dynamic memory allocation of a memory are generally done by brk(),sbrk(),mmap() etc .And you could easily check these using a strace tools.[ strace ./a.out ].And in general the number fo bytes allocated to you from a pool is mentioned just 8 bytes behind (in case of character) the starting address allocated to you and you could check it by just derefrencing it.It is a location which is generally fetched by the free call while freeing a memory from a pool.But there are a memory leakages in case of dynamic memory allocation in C. Please, correct me if I am wrong. And i am bit uncertain about the so called " featuring of a, b and c"