On Wed, Mar 27, 2002 at 12:13:02AM +0000, kevin lyda wrote:
> now i free location 30. that means there's a 10 byte hole in the heap.
> now different malloc implementations work different ways, but let's say
> this one will return 30 and 35 the next time i reserve two 5 byte chunks.
> no sbrk calls. in addition, since only 40 bytes were allocated, chances
> are malloc actually allocated an entire page on the first call.
A single page is the smallest amount that malloc can request from the
OS so it will have allocated a full page from which later allocations
will be made.
> the reserve suggestion wouldn't lead to a greater chance for leaks as
> it's just a hint to malloc's internals as to how much memory is about to
> be reserved. it could even be more efficient as it can lead to just one
> sbrk call instead of several (which is also why some programs actually
> fire off one large malloc and manage the pool themselves).
GNU malloc will use mmap to map /dev/null into your address space
and allocate memory out of that if the amount you request is above a
certain threshold. When you free this memory it's unmapped and
returned to the OS, unlike when you free memory allocated with sbrk.
Reserving memory as Kevin suggests could be helpful if you need to
make a large number of small allocations on a temporary basis.
 as far as I know it's Doug Lea's malloc, see
"That would preempt a bunch of problems involved in trying to reconstruct
exactly how the Perl 5 parser thinks, which nobody entirely understands."
Larry Wall, 2001/04/20, perl6-language at perl.org
"Finger to spiritual emptiness underlying everything." -- How a Japanese C
manual referred to a "pointer to void".
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!