🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #19984

Re: When to HLock

#19984
From: David Phillip Oster
Date: Thu, 08 Oct 1987 19:11
20 lines
1545 bytes
In article <2961@husc6.UUCP> fry@huma1.UUCP (David Fry) writes:
>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);

Wrong. The arguments of a function are fully evaluated before the function
gets called.  (**TheText).nLines evaluates to an Integer, and integers are
passed by value in C.

Now if you had said (**TheText).lineStarts then you would have been
correct, since arrays are passed by reference in C. The address of the
lineStarts array would be computed, NewWindow would get called,
shuffle memory, and the address would be bogus by the time NewWindow
got around to using it.
Technical Details
Message-ID: <21206@ucbvax.BERKELEY.EDU>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!sdcsvax!ucbvax!dewey.soe.berkeley.edu!oster
References: <960@mntgfx.MENTOR.COM> <2961@husc6.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!sdcsvax!ucbvax!dewey.soe.berkeley.edu!oster
From: oster@dewey.soe.berkeley.edu (David Phillip Oster)
Newsgroups: comp.sys.mac
Subject: Re: When to HLock
Message-ID: <21206@ucbvax.BERKELEY.EDU>
Date: Thu, 8-Oct-87 15:11:23 EDT
Article-I.D.: ucbvax.21206
Posted: Thu Oct  8 15:11:23 1987
Date-Received: Sun, 11-Oct-87 09:18:04 EDT
References: <960@mntgfx.MENTOR.COM> <2961@husc6.UUCP>
Sender: usenet@ucbvax.BERKELEY.EDU
Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster)
Organization: School of Education, UC-Berkeley
Lines: 20