When will malloc use sbrk?

Mike McGaughey mmcg at bruce.OZ
Tue May 8 01:25:11 AEST 1990


Hi,

I have a memory allocator and garbage collector which uses sbrk(2) to
directly grab blocks of space (this is so I can control the
alignment of blocks, so conversion from a pointer into a block to the
head of a block is fast).  Blocks are a multiple of the page size.

I also need malloc(3) - because things
like curses and stdio use it.  However, it would be nice to be able to
check whether malloc will need to use sbrk() before calling malloc -
that way, I can give malloc large, aligned chunks of memory, to reduce
fragmentation.

(1) Is there any simple way to do this?  Is it possible, for example,
to look up the size of the largest free block currently available to malloc?
Or do I have to write my own malloc and link that in instead?

(2) Will malloc fail if the space given to it is not contiguous (as other
routines use sbrk)?  When coalescing blocks?

Oh, (BSD4.3, Pyr 90x), and (BSD 4.1z, VAX 11/780).

Mike, who doubts it's gonna be simple.
--
Mike McGaughey			ACSNET:	mmcg at bruce.cs.monash.oz

"It's today!" said Piglet.
"My favorite day," said Pooh.



More information about the Comp.unix.wizards mailing list