Memory allocation techniques

Dave Hammond daveh at marob.MASA.COM
Thu Sep 15 02:09:25 AEST 1988


A popular PD program performs its own memory management, satisfying
memory requests from its heap, unless the request exceeds the current
heap size.  At that point additional core is allocated to satisfy the
oversized requirement.

In earlier versions, memory was allocated using sbrk(), and all subsequently
free'd space was returned to the heap. I notice a more recent version is
using malloc() to allocate its memory and only pooling larger chunks of
free'd memory (chunks smaller than 1K are pointedly trashed -- the code calls
them `Wasted').

Questions:

(1) Why the switch from sbrk() to malloc()?  Speed ?  Portability ?
    Dependability ?  I would think adding heap management on top of
    malloc would render malloc's own heap management useless.

(2) Why `waste' smaller chunks?  Since the code uses a first-fit algorythm,
    is this a trade-off between the time spent weeding through smaller chunks
    and the core wasted by the trashed chunks ?

Dave Hammond
  UUCP: uunet!masa.com!{dsix2,marob}!daveh
DOMAIN: dsix2!daveh at masa.com
----------------------------------------------------------------------------



More information about the Comp.lang.c mailing list