Re: unlinking...and calloc

From: Dean Gaudet <dgaudet-list-squid-dev@dont-contact.us>
Date: Mon, 29 Dec 1997 10:20:51 -0800 (PST)

--MimeMultipartBoundary
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Mon, 29 Dec 1997, Andres Kroonmaa wrote:

> Can you guys explain me what happens when I ptr=calloc("1 chunk", "of say 16MB")
> work on it, then free(). process SIZE does not drop after free(). Feels like libmalloc
> sets freed memory aside in hope that it would be reused. What about the case that
> malloc of this size never happens again? Would this amount of VM be simply wasted, or
> is libmalloc clever enough to reuse this memory for smaller chunks? (eg. gnumalloc?)
> Would it be more clever to code it to ptr=calloc("say 2048 chunks","of 8KB each"),
> is there any difference? Does libmalloc keep track of such allocation differently?

It depends on the OS and libc in use... The original method of getting
memory under unix was to use brk()/sbrk(). It's essentially impossible to
return memory acquired that way because you can only return stuff from the
top of the heap. Some newer unixes, like Linux and FreeBSD, actually
allocate memory by using anonymous mmap()ings. This can be freed by doing
an munmap. But to do so would cost a system call... and usually that's
not worth it, instead it's just kept around on a free list and reused by
future malloc()s. If you've got a specific application that requires a
huge whack of ram and then frees it and keeps going then you're probably
best off using mmap()/munmap().

Dean

--MimeMultipartBoundary--
Received on Tue Jul 29 2003 - 13:15:45 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:11:31 MST