sbrk(2) question

Richard Tobin richard at aiai.ed.ac.uk
Fri Mar 15 21:59:25 AEST 1991


In article <2045 at necisa.ho.necisa.oz.au> boyd at necisa.ho.necisa.oz.au (Boyd Roberts) writes:
>|        sbrk(100000);
>|        printf("hello world\n");
>|        sbrk(-100000);

>Well, I thought everybody new that sbrk(2) and malloc(3) just
>don't mix.

There is no reason for sbrk() and malloc() to "not mix" provided you're
careful not to free memory you didn't allocate.  On the other hand,
there's not usually a good reason to not just use malloc().

>Odds on printf(3) calls malloc and gets some memory
>whose address is > sbrk(0) + 100000*.

Yes, this is what happens.  Malloc() uses sbrk() to get some memory,
and the user's sbrk() frees it.

-- Richard
-- 
Richard Tobin,                       JANET: R.Tobin at uk.ac.ed             
AI Applications Institute,           ARPA:  R.Tobin%uk.ac.ed at nsfnet-relay.ac.uk
Edinburgh University.                UUCP:  ...!ukc!ed.ac.uk!R.Tobin



More information about the Comp.unix.questions mailing list