linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: leo mueller <llug.dan@googlemail.com>
To: Vadiraj <vadiraj.cs@gmail.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: problems with free()
Date: Tue, 28 Apr 2009 13:10:11 +0200	[thread overview]
Message-ID: <c93f91ee0904280410p76ef99dfye5ef0a6cb98de2af@mail.gmail.com> (raw)
In-Reply-To: <6eee1c40904280341n4e332026i7d9800fd4f8059b4@mail.gmail.com>

hi vadiraj,

thanks for your answer! first i thought about that, too, but if i do a
simple ...

char *x = (char *) malloc(1024 * 1024 * 100);
memset(x, 0, 1024 * 1024 * 100);
free(x);

... and put some sleeps in between (& before return)... i can see (->
htop) that
the % of mem is decreasing during runtime.... hmm...

2009/4/28 Vadiraj <vadiraj.cs@gmail.com>:
>
> On Tue, Apr 28, 2009 at 2:50 PM, leo mueller <llug.dan@googlemail.com>
> wrote:
>>
>> hi all,
>>
>> i got a little problem with free() ... i am allocating mem for a
>> special struct and putting it afterwards
>> into a linked list. allocating works fine, but freeing not. i'm
>> tracking the program with htop. after
>> allocating, the percentage of mem usage stays constant ...
>>
>> the test-file is attached.
>>
>> any help is appreciated. big thanks :)
>
> free() will put the chunk into the free pool of the process and not free
> away from the
> process. When you do a malloc again it would first try from the free pool,
> if it finds
> the size requested in the free pool it will give you the same.
> Hence you would not see any change.
>
> You can check that by, freeing an address and then requesting the same size.
> You will see that address freed and address allocated will be same in most
> of
> the case.
>
> Hope this helps.
>

  parent reply	other threads:[~2009-04-28 11:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <c93f91ee0904280218o2f844cd0u2262db407ca8f468@mail.gmail.com>
2009-04-28  9:20 ` problems with free() leo mueller
     [not found]   ` <6eee1c40904280341n4e332026i7d9800fd4f8059b4@mail.gmail.com>
2009-04-28 11:10     ` leo mueller [this message]
2009-04-28 14:48       ` Trevor Woollacott [ MTN - Innovation Centre ]
2009-04-28 11:22   ` Bert Wesarg
2009-04-28 12:52     ` leo mueller

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=c93f91ee0904280410p76ef99dfye5ef0a6cb98de2af@mail.gmail.com \
    --to=llug.dan@googlemail.com \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=vadiraj.cs@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).