Re: problems with free()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>:
>
> On Tue, Apr 28, 2009 at 2:50 PM, leo mueller <llug.dan@xxxxxxxxxxxxxx>
> 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.
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux