Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: Re: Another toolbox gotcha Message-ID: <7058@hoptoad.uucp> Date: 21 Apr 89 17:24:00 GMT References: <20-Apr-89.152339@192.41.214.2> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Organization: Eclectic Software, San Francisco Lines: 37 In article <20-Apr-89.152339@192.41.214.2> amanda@lts.UUCP (Amanda Walker) writes: >Rule: Always remove a resource before you replace it with something else. > >History: I had written a couple little routines that maintained a settings >file, which had about three resources in it. > >There's this note under "AddResource" that says you should make sure that >another resource with the same ID. My mistake was in reading this as >advice instead of literal truth. As it happens, the Resource Manager >will quite happily give you as many resources with the same type and ID >as you ask for, and "GetResource" will only find the first one, since >it's the first in the resource map... Generally good advice, but I believe it's even more efficient to simply change the existing resource, rather than remove it then add a new copy. There's less rearrangement of the resource map involved. Not only is there a time penalty for adding and deleting resource map entries, it may well require resizing handles used to store the resource map information, which could potentially lead to problems for a large resource file or a situation where little free RAM remains. (It shouldn't, since all you're doing is shrinking it then growing it back out to the same size, but it's best to be cautious. For instance, your program gets executed between shrinking and growing, and it could inadvertently put a locked block into the "free tail" of the old resource map.) However, as a recent Tech Note points out, don't call ChangedResource over and over without updating the resource file. Due to a system bug, the file will grow every time you call ChangedResource, and only be restored to its proper size when you call UpdateResFile (or close the resource file). This isn't relevant to your situation, Amanda, since you close the file right away after changes, but a lot of us do leave our application preferences files always open. (Why not?) -- Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim "God must be a Boogie Man." -- Joni Mitchell