Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!dewey.soe.berkeley.edu!oster From: oster@dewey.soe.berkeley.edu (David Phillip Oster) Newsgroups: comp.sys.mac.programmer Subject: Re: ROM Unlocks handles (was Re: How to Argue Technical Points) Message-ID: <33034@ucbvax.BERKELEY.EDU> Date: 6 Dec 89 05:04:51 GMT References: <2744@dogie.macc.wisc.edu> <3838@atr-la.atr.co.jp> <32977@ucbvax.BERKELEY.EDU> <3842@atr-la.atr.co.jp> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) Organization: School of Education, UC-Berkeley Lines: 46 In article <3842@atr-la.atr.co.jp> alain@atr-la.atr.co.jp (Alain de Cheveigne) writes: >But hassle it is. Is there a better way ? Yes. What complexity, and slowness! (all those unnecessary MovHHi()s can really slow a program down.) I too use very similar data structrues: handles in the RefCons of my windows that themselves reference other handles. If a field referenced by an O.S. call is small, copy it. If it is large, lock the owning handle during the call. Do not write your own routines to take pointers into handles, instead, if you must do such a thing, do it by passing a handle an an offset. (Often you can just pass the handle, since the routine knows its offset.) Here is an example, from a program that uses a window handle which references two pixmaps. (I keep the current window handle in a global variable called "theDoc", by analogy with "thePort".) Notice, no need for any HLocks or MoveHHis. /* DocDispose - discard our window */ DocDispose(){ if(NIL != (**theDoc).newPix){ if(NIL != (**(**theDoc).newPix).baseAddr){ DisposPtr((**(**theDoc).newPix).baseAddr); (**(**theDoc).newPix).baseAddr = NIL; } DisposPixMap((**theDoc).newPix); } if(NIL != (**theDoc).oldPix){ if(NIL != (**(**theDoc).oldPix).baseAddr){ DisposPtr((**(**theDoc).oldPix).baseAddr); (**(**theDoc).oldPix).baseAddr = NIL; } DisposPixMap((**theDoc).oldPix); } DisposHandle((Handle) theDoc); DisposeWindow(thePort); } Actually, this does bring up a question. Inside Mac Vol 5 doesn't say precisely which fields are disposed when you call DisposPixMap(). --- According to the Constitution, the Constitution is unconstitutional: --- David Phillip Oster --U.S.Constitution I.10.1: "No State shall Arpa: oster@dewey.soe.berkeley.edu --enter into any treaty, alliance, or Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu -- confederation..."