Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!hsdndev!wuarchive!sdd.hp.com!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!apple!vsi1!zorch!mykes From: mykes@zorch.SF-Bay.ORG (Mike Schwartz) Newsgroups: comp.sys.amiga.programmer Subject: Re: Two questions about memory allocation Message-ID: <1991Jan11.074912.16800@zorch.SF-Bay.ORG> Date: 11 Jan 91 07:49:12 GMT References: <8135@ucdavis.ucdavis.edu> Organization: SF-Bay Public-Access Unix Lines: 41 In article <8135@ucdavis.ucdavis.edu> zerkle@iris.ucdavis.edu (Dan Zerkle) writes: >I recently wrote a vector graphics package that had to allocate and >de-allocate huge amounts of small structures with malloc. I noticed >that it seemed to be running awfully slowly for some reason. When I >wrote my own memory manager instead, the program ran three times >faster. People running similar stuff on Unix (for the same class) >noticed that their programs didn't spend a lot of time on memory >management (according to the profiler). > >So: Why does the Amiga spend so much time fooling around with memory >management? Is the behavior I noted typical? > >Also, this same program's memory manager would allocate a large chunk >of memory at the beginning of the program (and in the middle, >actually), but I never bothered to de-allocate the memory before >exiting. I never noticed any problems with this, and the status line >showed as much memory before execution as after. That doesn't mean >that there wasn't a potential for problems. Does anybody know about >this? Was I doing a bad thing? Should I explicitly de-allocate the >memory before exiting, or just count on "the system" to take care of >it? > >If it matters: A3000 under 2.02, Aztec C 5.0d. > > Dan Zerkle zerkle@iris.eecs.ucdavis.edu (916) 754-0240 > Amiga... Because life is too short for boring computers. I can't answer the first question, but if there are a lot of "little" allocated chunks of memory, your program is certainly spending a lot of CPU time calling free(). Under Manx, the malloc() and free() routines are their own "glue" routines wrapped around the Amiga memory manager. One feature of these, as well as all the other routines that look like the ones on Unix, is that the exit() routine in the Manx library is smart enough to clean up for you when you exit. This means you can exit() with memory allocated, files openned, etc., and exit() will clean up for you. On the other hand, if you call AllocMem() or Open(), YOU will have to clean up or you WILL see a memory leak (less memory available after you run and exit). Cheers Mykes