Re: [Q]



On 2002.01.28 00:37:36 +0000 Julian M Catchen wrote:
> I am not sure how Balsa manages its memory, but you can change the size of 
> a memory segment to a larger or smaller one with realloc().
> 

That's a diferent chapter. C programs see malloc/free/realloc which is the
std C memory management API. glibc in turn uses the system call brk() to
change the amount of memory allocated by the kernel to the program.
brk() is a bit heavy cause it means (on x86) changing the page tables for
the thread. that's why glibc chooses to do as little brk() as possible by
usually not giving back memory. instead, as it needs to keep booking for the
alloc()ed memory it just keeps the pages in the free pool. realloc() is just 
done out of that memory pool. if there's a big enough
chunk next to the chunk being increased it uses that, if there is a big
enough chunk for the requested space somewhere it *copies* stuff there,
if not it brk()s more memory and copies stuff there.
point being :) , we don't control how glibc handles memory allocation.
realloc/free doesn't always mean we're giving memory back to the kernel
but to our own free pool.

-- 
Carlos Morgado - chbm(at)chbm(dot)nu - http://chbm.nu/ -- gpgkey: 0x1FC57F0A
http://wwwkeys.pgp.net/ FP:0A27 35D3 C448 3641 0573 6876 2A37 4BB2 1FC5 7F0A
Software is like sex; it's better when it's free. - Linus Torvalds



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