All of lore.kernel.org
 help / color / mirror / Atom feed
From: ishubist@gmail.com (Abhishek Bist)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Basic question about malloc
Date: Thu, 23 Apr 2015 11:23:56 +0530	[thread overview]
Message-ID: <20150423055356.GA9678@localhost.localdomain> (raw)

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<stdio.h>
#include<stdlib.h>

#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"

             reply	other threads:[~2015-04-23  5:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-23  5:53 Abhishek Bist [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-04-23  1:52 Basic question about malloc 慕冬亮
2015-04-23  3:03 ` Valdis.Kletnieks at vt.edu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150423055356.GA9678@localhost.localdomain \
    --to=ishubist@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.