Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!snorkelwacker.mit.edu!bloom-beacon!vaxeline!bootsie!olson From: olson@bootsie.uucp (Eric K. Olson) Newsgroups: comp.sys.mac.programmer Subject: Re: Is this possible with the Resource Manager? Message-ID: <1991Feb20.101151.22358@bootsie.uucp> Date: 20 Feb 91 10:11:51 GMT References: <1CE00001.ed5n0r@tbomb.ice.com> <12158@goofy.Apple.COM> Organization: Lexington Software Design, Lexington, MA Lines: 85 In a recent article, Larry Rosenstein (lsr@Apple.COM) writes: >[Re: Reading data from disk while resource in memory] > > You have to do this without calling DetachResource. > One way that comes to mind is: > >if (*resHand != NULL) { > /* save current contents */ > oldSize = GetHandleSize(resHand); > save = NewHandle(oldSize); > BlockMove(*resHand, *save, oldSize); > > EmptyHandle(resHand); > LoadResource(resHand); /* re-load disk copy */ > > diskCopy = resHand; > HandToHand(diskCopy); /* make a copy of it */ ^^^^^^^^ HandToHand(&diskCopy); > > /* restore original version */ > SetHandleSize(resHand, oldSize); > BlockMove(*save, *resHand, oldSize); > DisposHandle(save); > } > This code is more like what I was looking for. I definitely prefer this to the rule-breaking solution I posted earlier. I've tried it (with the fix to HandToHand()) and it seems to work fine. Thanks Again, Larry! It's worth noting that in THINK C (and probably MPW), the call to HandToHand() in the included code below should be: HandToHand(&diskCopy); It occurs to me that calling DetachResource() on _any_ resource in the currently running Application could be dangerous (if that resource has been GetResource()'ed by some other part of your program). It might help to think of my application as a parasitic FKEY resource editor (it's not-- it's the Prepare() View Editor) that can't really know what resources are in use by the host application. (Similarly, the View Editor is intended to work compiled into any other application, whose objects may be using resources). Is it possible to know what resources have been gotten and have since been purged? Or gotten with SetResLoad(FALSE)? You can't call DetachResource() on those, either, I presume, although you can HandToHand() it and return the copy, then EmptyHandle() the resource handle if it was empty before. Or I could call HPurge() on the resource handle (if it was empty before), so it might remain in memory until the next time it's GetResource()'ed. Is this kosher? /* Detach a resource, leaving previous references around */ Handle MyDetachResource(Handle aResHandle, Boolean wasLoaded) { Handle aDataHandle; aDataHandle = aResHandle; HandToHand(&aResHandle); if (!wasLoaded) { HPurge(aResHandle); OR EmptyHandle(aResHandle); } return aDataHandle; } -Eric -- Eric K. Olson, Editor, Prepare() NOTE: olson@bootsie.uucp doesn't work Lexington Software Design Internet: olson@endor.harvard.edu 72A Lowell St., Lexington, MA 02173 Uucp: harvard!endor!olson (617) 863-9624 Bitnet: OLSON@HARVARD