Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!huma1!fry From: fry@huma1.HARVARD.EDU (David Fry) Newsgroups: comp.sys.mac Subject: Re: When to HLock Message-ID: <2961@husc6.UUCP> Date: Thu, 8-Oct-87 11:41:32 EDT Article-I.D.: husc6.2961 Posted: Thu Oct 8 11:41:32 1987 Date-Received: Sun, 11-Oct-87 01:48:36 EDT References: <960@mntgfx.MENTOR.COM> Sender: news@husc6.UUCP Reply-To: fry@huma1.UUCP (David Fry) Organization: Harvard Math Department Lines: 30 In article <960@mntgfx.MENTOR.COM> tomc@mntgfx.MENTOR.COM (Tom Carstensen) writes: >Question: Do you need to HLock in the following >kind of situation?: > >TEHandle TheText; >lines = (**TheText).nLines No, because you're only accessing memory and assigning it to a stack variable, lines. You need to HLock when memory may be moved. Inside Mac has a list of Toolbox calls that can move memory, but if you don't want to look it up you can call HLock before a Toolbox routine (better to look it up). Suppose, however that you wanted to create a NewWindow and the refcon was going to be the number of lines in the TEHandle, then you must HLock before calling the NewWindow because NewWindow may move memory: MoveHHi(TheText); HLock(TheText); myWindow = NewWindow( , ,...,(**TheText).nLines ); HUnlock(TheText); "How to Write Macintosh Software" by Scott Kastner (sp?) is a great source for tidbits like this. David Fry fry@huma1.harvard.EDU Department of Mathematics fry@harvma1.bitnet Harvard University ...!harvard!huma1!fry Cambridge, MA 02138