Subject: Re: use of gnumalloc?
To: None <>
From: Mark P. Gooderum <>
List: current-users
Date: 11/17/1994 22:57:35
According to Luke Mewburn:
> Is there any need to have gnumalloc in the tree anymore?
> Do programs depend on some feature or quirk that it provides
> that the 4.4BSD/NetBSD malloc doesn't? If not, wy don't we
> depreciate gnumalloc's use by programs (although keep it in
> libc for programs that need it.) Or is the BSD one a memory
> hog and the gnu one not?

Yes.  The BSD malloc algorithm is very simple and can be very
space inefficent (real allocation unit is effectively powers of
two with some minor fudges).  I rewrote a debugging malloc (interesting
trick considering that the BSD malloc normally doesn't have an allocated
heap, it barely has a free heap at all really), that
did almost everything Purify did and some more based on this malloc,
so I'm a little familiar with it.

The GNU malloc is more space efficient, but has much more processing
overhead and is more complex.

> I've compiled up XFree86-3.1 and it uses -lgnumalloc, and one
> of the config options is Malloc0ReturnsNull NO. Looking at the
> source for gnumalloc it appears that doing malloc(0) returns
> a pointer that you can realloc, free, etc. From looking at
> libc/stdlib/malloc.c, NetBSD malloc has a similar functionality
> (because I can't see a special case for nbytes==0.) I haven't
> had time to whip up test programs to check this though.

Setting this to NO is a BSD compatibility concession.  Many old programs
assume that malloc/realloc(0) return a valid node than can be 
played with.  There's some other historical ugliness in the BSD malloc
like re-mallocing the last freed block.

So it's worth keeping.  If you build anything that runs a long time
and frequently allocates and frees varying sized blocks (like X...),
you'll probably benefit a lot from the GNU malloc.
Mark P. Gooderum			   USSnail:  Good Creations
Senior Consultant - Operating Systems Group	     3029 Blackstone Ave. So.
  "Working hard to be hardly working..."	     St. Louis Park, MN 55416
EMail:		   Voice:    (612) 922-3953
Interactive:	   Fax:	     (612) 922-2676