Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!apple!keith From: keith@Apple.COM (Keith Rollin) Newsgroups: comp.sys.mac.programmer Subject: Re: Linked Lists: Handles or Pointers? Message-ID: <48445@apple.Apple.COM> Date: 24 Jan 91 23:33:19 GMT References: <.664719435@rw8.urc.tue.nl> <1991Jan24.145729.12853@nada.kth.se> Organization: Apple Computer Inc., Cupertino, CA Lines: 36 In article <1991Jan24.145729.12853@nada.kth.se> d88-jwa@aswad.nada.kth.se (Jon W{tte) writes: >In article <.664719435@rw8.urc.tue.nl> rcbaab@urc.tue.nl writes: > >If you use a dereferenced handle (like, pass it to the ToolBox) >you'll have to lock it. If you lock a handle, it's nice to do it >at the top of the heap. Thus: > > char state ; > > state = HGetState ( handle ) ; > MoveHHi ( handle ) ; > HLock ( handle ) ; > DoSomething ( * handle ) ; > HSetState ( handle , state ) ; > >This is the recommended way of doing it. For elaborate cases, where the stuff between HLock and HSetState can be quite lengthy or allocate non-relocatable blocks, I'd agree. But for small cases, doing the MoveHHi is not worth it. MoveHHi is an expensive call in terms of time, so you don't want to call it blindly. MacApp includes a procedure called LockHandleHigh that does all of the setup for you. In MacApp 3.0, which will return the old state for you, the above would look like this: state = LockHandleHigh(handle); DoSomething(*handle); HSetState(handle, state); -- ------------------------------------------------------------------------------ Keith Rollin --- Apple Computer, Inc. --- Developer Technical Support INTERNET: keith@apple.com UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith "Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions