Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!elroy.jpl.nasa.gov!decwrl!uunet!mcsun!ukc!edcastle!aiai!richard From: richard@aiai.ed.ac.uk (Richard Tobin) Newsgroups: comp.unix.questions Subject: Re: sbrk(2) question Message-ID: <4319@skye.ed.ac.uk> Date: 15 Mar 91 11:59:25 GMT References: <1991Mar8.180132.12025@Think.COM> <4296@skye.ed.ac.uk> <6582@auspex.auspex.com> <4312@skye.ed.ac.uk> <2045@necisa.ho.necisa.oz.au> Reply-To: richard@aiai.UUCP (Richard Tobin) Organization: AIAI, University of Edinburgh, Scotland Lines: 23 In article <2045@necisa.ho.necisa.oz.au> boyd@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@uk.ac.ed AI Applications Institute, ARPA: R.Tobin%uk.ac.ed@nsfnet-relay.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin