Path: utzoo!attcan!uunet!ginosko!bbn!apple!agate!ucbvax!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: Re: Config File Resource Blues Message-ID: <7907@hoptoad.uucp> Date: 8 Jul 89 20:44:28 GMT References: <2002@dogie.macc.wisc.edu> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Organization: Eclectic Software, San Francisco Lines: 59 In article <2002@dogie.macc.wisc.edu> yahnke@vms.macc.wisc.edu (Ross Yahnke, MACC) writes: > /* Zap the old data as it is most likely out of date */ > dataHdl = GetResource('DATA', 128); > RmveResource(dataHdl); > WriteResource(dataHdl); > DisposHandle(dataHdl); You shouldn't call WriteResource after calling RmveResource. However, according to Inside Mac, WriteResource will do nothing if the handle isn't a resource, so this should not cause you any problems. Still, you ought to realize that after you call RmveResource, dataHdl is no longer a resource handle -- it's just an ordinary handle. However, as you can see from reading the description of RmveResource, you are right to call DisposHandle. (Sorry, Dean. If he calls ReleaseResource at this point, he's asking for trouble.) > aHdl = NewHandle(DATA_SIZE); > /* At this point I init aHdl w/the data structure > * that I've maintained, in preparation for > * writing it back out. > */ > AddResource(aHdl, 'DATA', 128, ""); > WriteResource(aHdl); > DisposHandle(aHdl); Here Dean Yu is correct to point out that you should not use DisposHandle. The actual handle that you pass to AddResource is inserted in the resource map; if you dispose of it, the resource map becomes bad. Future calls to GetResource will attempt to retrieve this handle, which is no longer valid after the DisposHandle. I want to point out that this is a very ineficient way of doing things. There's no need to remove and re-add the resource; you can just change it and call ChangedResource. This would reduce the memory operations involved in removing and re-adding (which can be quite significant, leading the entire resource map to be resized in RAM) and reduce the size and complexity of your routine. Your whole update routine would be just: aHdl = GetResource('DATA', 128); /* At this point I init aHdl w/the data structure * that I've maintained, in preparation for * writing it back out. */ ChangedResource(aHdl); WriteResource(aHdl); /* optional */ -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com Postal: 424 Tehama, SF CA 94103; Phone: (415) 495-2934 "Those Mayas were sacrificing not only pagan children, but baptized Christian children, for crying out loud! And they were carrying out those sacrifices, those barbarities, with great savagery, without giving the victims the benefit of the humane types of death that the European Church accorded even to heretics and witches during that century, such as burning at the stake." -- Matthew Rosenblatt, rec.arts.books