Re: memory management related system calls
From: Kasper Dupont (kasperd_at_daimi.au.dk)
Date: 09/04/03
- Next message: Kasper Dupont: "Re: pthreads & sockets"
- Previous message: Kasper Dupont: "Re: #!/usr/bin/my-onw-interpreter - how?"
- In reply to: VINAY: "memory management related system calls"
- Next in thread: Wolfram Gloger: "Re: memory management related system calls"
- Reply: Wolfram Gloger: "Re: memory management related system calls"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 04 Sep 2003 08:33:46 +0200
VINAY wrote:
>
> Hi all,
> linux kernel gives handle only to alter the heap size ( brk()
> syscall).
> What if I want to deallocate a chunk of memory within a heap ( i.e not
> on the boundaries of heap). Is there any syscall to do this ?
It is possible to use munmap, but I would strongly advice against it.
In particular if you intend to use brk again at a later time, it is
probably not a good idea to mess with it's allocations. Instead you
should use mmap to allocate rather than brk. There is a reason brk
is not in the posix standard.
> How does free () in glibc manage this.
That depends on how the memory was allocated. It can either allocate
using brk or mmap. For small allocations it will primarily use brk
and for large allocations it will use mmap. If it was allocated
using brk, free will put it on a free list for use by later calls of
malloc in the same process. It is never returned to the OS. In case
it was allocated with mmap it can be freed again using munmap. I
don't however know whether free actually does free the memory, or
whether it is put on the free list. You can find out by allocating
a large (a few MB) chunk, free it again, and look on the maps.
-- Kasper Dupont -- der bruger for meget tid paa usenet. For sending spam use mailto:aaarep@daimi.au.dk Their business was zero and it was shrinking.
- Next message: Kasper Dupont: "Re: pthreads & sockets"
- Previous message: Kasper Dupont: "Re: #!/usr/bin/my-onw-interpreter - how?"
- In reply to: VINAY: "memory management related system calls"
- Next in thread: Wolfram Gloger: "Re: memory management related system calls"
- Reply: Wolfram Gloger: "Re: memory management related system calls"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|