memory allocation

T. William Wells bill at proxftl.UUCP
Wed Sep 28 13:09:49 AEST 1988


In article <7105 at cdis-1.uucp> tanner at cdis-1.uucp (Dr. T. Andrews) writes:
: On free() calls, I trace the list until I find the block to be freed.
: If it isn't a valid block, it isn't free()d.  As the block is being
: freed, I coalesce the adjacent free block(s).  At most 3 blocks may
: be collected (the freed block and the ones immediately above and
: below).

Do I wish I could afford this kind of strategy!  :-) However,
what you are describing is *expensive*.  One might want to do
this kind of thing in a system where catching bugs is of the
essence, but any other use is likely to cost an unacceptable
amount of machine time, if one does much allocating.

:          It seems much better to do this work wen the block is freed
: (if ever) rather than to perform trash-mashing at malloc() time.

Given what you are doing, you should do the coalesce at free
time.  However, in systems where coalescing involves extra work,
it is usually better done at malloc time: this is generally more
efficient because some of the work may already be being done at
malloc time, and because the coalescing doesn't have to be done
until needed (if ever).  However, this is a general comment;
specific allocators may have different characteristics.

---
Bill
novavax!proxftl!bill



More information about the Comp.lang.c mailing list