On Tue, Sep 20, 2005 at 15:07:11 -0700, Bruce Yang wrote: > I want to know how malloc is implemented in Linux? > Use system call or other methods. > Who could give some links on how to implement C Libray is welcome! It's a library (glibc) function implemented using two syscalls -- setbrk and mmap. setbrk extends "heap" and is used for small allocations. The heap is never shrunken and malloc keeps list of holes in the heap in userspace. For large, where large means at least a page, mmap is called instead which attaches a chunk of memory to the area above heap. This memory is returned to the system by munmap. For links, you have the source of glibc, so look there. Also search the web for Jeff Bonwicks paper about Slab allocator. It's for kernel (Linux uses it too), but in the updated version he says they successfuly used the techique in userland too. -- Jan 'Bulb' Hudec <bulb@xxxxxx>
Attachment:
signature.asc
Description: Digital signature