Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!ucdavis!iris!lim From: lim@iris.ucdavis.edu (Lloyd Lim) Newsgroups: comp.sys.mac.programmer Subject: Re: Optimizing animation processing speed Message-ID: <8996@ucdavis.ucdavis.edu> Date: 18 May 91 22:26:39 GMT References: <1776@babcock.cerc.wvu.wvnet.edu> Sender: usenet@ucdavis.ucdavis.edu Reply-To: lim@iris.ucdavis.edu (Lloyd Lim) Organization: U.C. Davis - Department of Electrical Engineering and Computer Science Lines: 57 In article <1776@babcock.cerc.wvu.wvnet.edu> un020070@vaxa.wvnet.edu writes: >[...] > >In this animation, I am moving icons around on the screen. I >have two offscreen bitmaps. The first offscreen contains the >background art, which is slow to draw; this way, I only have to >draw it once. I continually CopyBits this whole bitmap into >the second bitmap. I draw the icons the second bitmap, then >copyBits the second bitmap onto the screen. This whole process >happens every event loop. (Slow as this sounds, I have reason >to believe that this is actually not the big time-consumer.) But you can still speed it up. Instead of copying the whole background over, keep track of where each icon was and just copy over little squares of the background. You could also take all the old squares, make a region out of them, and use that as the maskRgn in a CopyBits of the whole background. I'm not sure which would be faster. >Each time I plot an icon, I GetIcon it, then draw it using copyBits, >then ReleaseResource it. Now, if I'm not mistaken, this doesn't >actually purge the icon from memory, right? If something else needs >the memory it will write over it, but if nobody needs the memory, >the icon will hang around until the next cycle, and GetIcon will >just give me a handle to the icon in memory, right? IM says: "Given a handle to a resource, ReleaseResource releases the memory occupied by the resource data, if any, and replaces the handle to that resource in the resource map with NIL. The given handle will no longer be recognized as a handle to a resource; if the Resource Manager is subsequently called to get the released resource, a new handle will be allocated. Use this procedure only after you're completely through with a resource." Don't call ReleaseResource. If the resource is purgeable, it will stick around unless the memory is needed for something else. Icons aren't very big so if you're using the same ones over and over, you probably will want to load them once, save the handles, and make them unpurgeable (but not locked). Then just refer to them by the handles. >In doing the calculations for the animation, I frequently refer >to complex data structures by handles. Is this a particularly >slow way of doing things? Could I speed things up appreciably by >locking the handles and using more Pascal WITH statements? There isn't much to a handle dereference. Generally, using handles and keeping them unlocked as much as possible is a good thing to do. If you need to refer to a field with a call that moves memory, make a local copy of the field and use the copy in the call. If you need to use something larger and move memory, HGetState, HLock, and HSetState. WITHs and/or register variables (does Pascal have those?) might help a little. +++ Lloyd Lim Internet: lim@iris.eecs.ucdavis.edu America Online: LimUnltd Compuserve: 72647,660 US Mail: 215 Lysle Leach Hall, U.C. Davis, Davis, CA 95616