Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!lll-winken!sun-barr!newstop!sun!imagen!atari!apratt From: apratt@atari.UUCP (Allan Pratt) Newsgroups: comp.sys.atari.st Subject: Re: Malloc - what it really does (was: Re: SPUFILE 2.0, C questions) Message-ID: <1737@atari.UUCP> Date: 23 Oct 89 19:29:10 GMT References: <1322@engage.enet.dec.com> <1680@laura.UUCP> Organization: Atari Corp., Sunnyvale CA Lines: 24 klute%trillian.irb@unido.uucp (Rainer Klute) writes: >wallace@oldtmr.dec.com (Ray Wallace) writes: >From what I have found out Malloc (-1L) returns the *sum* of the >sizes of *all* free memory chunks. This is emphatically not the case, and never has been. The original answer was right: it returns the size of the LARGEST SINGLE CHUNK of free memory. A common way to find out how much memory there is in the system is to call Malloc(-1L) many times, each time allocating a chunk of the size it returns, until it returns zero. Then you report the answer and Mfree() all the chunks you allocated. Of course, Malloc(-1) is evil if you're in a multi-tasking environment, because in the time between the Malloc(-1) and actually allocating the block of the size it reported, you could be preempted and somebody else might allocate that block away from you! This is only one of a whole class of problems which a multitasking TOS would have to address: the single-thread, global, I-own-the-machine nature of TOS applications. ============================================ Opinions expressed above do not necessarily -- Allan Pratt, Atari Corp. reflect those of Atari Corp. or anyone else. ...ames!atari!apratt