Dynamic Storage Allocator Pros and Cons

Richard Harter rh at smds.UUCP
Sat Nov 24 17:31:51 AEST 1990


In article <1990Nov21.212147.20783 at diku.dk>, njk at diku.dk (Niels J|rgen Kruse) writes:
> rh at smds.UUCP (Richard Harter) writes:

> >(A)    All invalid size requests (zero, negative, too large) are trapped.
> ---------------------------------------------------^^^^^^^^^
> Try ``getsp (2147483646,0)''.   ;-)

	??? What machine is this on?  It worked fine on the
	a couple of tests.

> Another bug: The return value of malloc in GETNODES is never
> checked, so if malloc returns NULL, getsp dump core quite
> ungracefully.

	Quite right, thanks for pointing it out -- not that it
	is what one would call a high probability bug.

	
> PS: You call it a Best Fit allocator.  This is only true for
> sizes smaller than 1Kb, for larger blocks the selection
> strategy is LIFO.  This means that the memory utilization
> achieved is quite a lot lower than that of a true Best Fit
> storage allocator.

	Color me lazy.  I never bothered with coding up a fast
	big block best fit component.  For that matter I'm not
	sure that it is warranted.  If the block request sizes
	are "large" relative to the size of managed memory the
	best fit is not much better than lifo.  Best fit gains
	in two ways -- the percentage of fragments is smaller
	because of exact fits and the fragment size distribution
	is skewed to favor very small or very large blocks.
	Both advantages are much less when the request sizes
	are "large".

> PPS: If you change the #define for BKSZ to
> ``( 65472 & (unsigned)-1/2 )'', the code will also work on a
> Xenix286 system in large memory model.

Cute hack.  Actually I never work in Xenix286 -- God has been
merciful.

PS:  If anyone has a better allocator and wants to post it
(or make it available vit FTP) I will be glad to pick it up
and try it out.  

-- 
Richard Harter, Software Maintenance and Development Systems, Inc.
Net address: jjmhome!smds!rh Phone: 508-369-7398 
US Mail: SMDS Inc., PO Box 555, Concord MA 01742
This sentence no verb.  This sentence short.  This signature done.



More information about the Comp.lang.c mailing list