Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uwm.edu!ux1.cso.uiuc.edu!pequod.cso.uiuc.edu!dorner From: dorner@pequod.cso.uiuc.edu (Steve Dorner) Newsgroups: comp.sys.mac.programmer Subject: Re: Large Programs and Memory Management Questions Message-ID: <1991Apr24.170354.20749@ux1.cso.uiuc.edu> Date: 24 Apr 91 17:03:54 GMT References: <1991Apr24.122618.13791@bmers95.bnr.ca> Sender: usenet@ux1.cso.uiuc.edu (News) Organization: University of Illinois at U-C Lines: 42 >There is the "unload all your segments every time through your event loop" >effective method or are there other better methods? If you know your code in and out, you could unload segments on the fly. Just be darn careful you don't unload a segment that holds anything on the current call stack. You're PROBABLY better off not doing this, unless you have a very special program, since it will require you to do a lot of careful bookkeeping on what routines call what and what segments they're in, and will probably not gain you much anyway. >Should your application periodically compact the heap to keep it from >getting fragmented? No. Won't do you any good. Just make sure you don't have relocatable blocks lying around and you'll be fine. >What would happen if there was not enough memory to load a CODE segment? La Bombe. >And more importantly, how do you prevent >this from happening There are a couple of ways. You can reserve a goodly chunk of memory, and release it in your GrowZone procedure; this will cover your posterior often. The other way is to have intimate knowledge of inter-segment references, and always preflight such calls by checking if there is enough memory to load the needed segment. I think MacApp does this. I doubt it's practical for the average developer, unless you come up with an elaborate segmentation system. if (EnoughMemoryForCodeSegment(32)) CallSomeFunction(withSomeArg); else RefusePolitely(); would get real old if it weren't being done automagically by your development environment. I'd suggest you get a copy of "How to Write Macintosh Software" by Scott Knaster. It's a big help with issues like this. -- Steve Dorner, U of Illinois Computing Services Office Internet: s-dorner@uiuc.edu UUCP: uunet!uiucuxc!uiuc.edu!s-dorner