Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!purdue!bu-cs!dartvax!eleazar.dartmouth.edu!earleh From: earleh@eleazar.dartmouth.edu (Earle R. Horton) Newsgroups: comp.sys.mac.programmer Subject: Re: A Better malloc()? Keywords: autofree Message-ID: <14381@dartvax.Dartmouth.EDU> Date: 12 Jul 89 22:08:54 GMT References: <214@intek01.UUCP> Sender: news@dartvax.Dartmouth.EDU Reply-To: earleh@eleazar.dartmouth.edu (Earle R. Horton) Organization: Thayer School of Engineering Lines: 33 In article <214@intek01.UUCP> mark@intek01.UUCP (Mark McWiggins) writes: >We have a couple of applications that we've moved over from the Unix/DOS >world that do a lot of memory allocation. They don't free up what they've >allocated on exit, since Unix and DOS both get that back automatically. >Of course, this is a problem on the Mac since (as I understand it) MPW's >malloc() allocates a nonrelocatable block that just sticks there forever >until explicitly deallocated. This is just not true. All storage is reclaimed when you call exit() or ExitToShell(). There is a page in the MPW C manual describing exactly how malloc() works. I suggest you read both this and the Memory Manager chapter of Inside Macintosh to see what is going on when you call malloc() on the Macintosh. If your programs do a lot of memory allocation, particularly using small blocks, then you might want to consider using relocatable blocks for this purpose. These are extremely helpful if you find yourself free-ing and reallocating memory a lot. Under these conditions, using nonrelocatable blocks such as those obtained from malloc() can promote heap fragmentation. >Has somebody reimplemented malloc() to work more smoothly in the Mac world? >What I want is a free_everything() call to use when I exit. The problem is not that malloc() is inefficient on the Mac, but rather that the use of relocatable blocks, as obtained from NewHandle(), can be much more efficient when you need to reallocate space. If you do not reallocate space, then using MPW malloc() is perfectly safe. Exit() will free everything, trust me. Earle R. Horton "People forget how fast you did a job, but they remember how well you did it." Salada Tag Lines