Malloc problems

Henry Spencer henry at utzoo.uucp
Thu May 26 07:16:00 AEST 1988


There is no need to mess with the insides of malloc for this.  It is
really pretty easy to implement a scheme in which you get an "area" by
calling newarea() and then get data "within" the area by calling, say,
areaalloc() with the area and the size you want.  The area is in fact
a data structure which keeps pointers to everything you allocate through
it.  areaalloc() just invokes malloc() and adds a pointer to the result
to the area.  You can then deallocate everything in the area by calling
a function that just goes through the area calling free() on everything.
Note that the "area" doesn't actually correspond to a contiguous block
of storage, despite its name.

You can add arbitrary bookkeeping to the area functions easily.  The
major advantage is this stuff can be fully portable, which the insides
of malloc (and hence, changes to the insides of malloc) are *NOT*.



More information about the Comp.lang.c mailing list