[comp.unix.questions] When will malloc use sbrk?

mmcg@bruce.OZ (Mike McGaughey) (05/07/90)

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@bruce.cs.monash.oz

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

dold@mitisft.Convergent.COM (Clarence Dold) (05/08/90)

in article <2127@bruce.OZ>, mmcg@bruce.OZ (Mike McGaughey) says:

-> 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,

It might be as simple as compiling with -lmalloc, which is an optional
malloc library that does sbrk of large, contiguous memory space.
-- 
---
Clarence A Dold - dold@tsmiti.Convergent.COM            (408) 435-5293
               ...pyramid!ctnews!tsmiti!dold        FAX (408) 435-3105
               P.O.Box 6685, San Jose, CA 95150-6685         MS#10-007