Very confused about malloc in Linux, Help!!!

Carlos O'Donell carlos@systemhalted.org
Mon Oct 11 13:49:00 GMT 2010


2010/10/9 Shigang Zan <zanshigang@hotmail.com>:
> So my question is:
>
> 1. What malloc did do to cause scenario 2? Both 1 and 2 are multi-thread program.

Malloc may be using already allocated arenas to allocate your blocks.
This shouldn't be a problem and will not effect the performance of
your program.

> 2. Can malloc free memory well in scenario 2?

Yes.

If you have a problem you need to provide a test case.

Malloc may keep an arena around like a cache to avoid future mmaps.

Please keep in mind that POSIX says free will ensure that space is
"made available for further allocation," but it doesn't say it is
given back to the OS.

You have to allow the OSs VM to handle things.

If you need more explicit control, write your own malloc.

Cheers,
Carlos.



More information about the Libc-help mailing list