Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!think.com!hsdndev!husc3.harvard.edu!husc9.harvard.edu!aoki From: aoki@husc9.harvard.edu (Edwin Aoki) Newsgroups: comp.sys.mac.comm Subject: Re: CommToolBox Keywords: tools source hlock memory Message-ID: <1991May23.090830.1128@husc3.harvard.edu> Date: 23 May 91 13:08:29 GMT References: <1983@prcrs.prc.com> Sender: aoki@husc9.harvard.edu (Edwin Aoki) Followup-To: Terry Neely's Article <1983@prcrs.prc.com> Organization: Harvard University Science Center Lines: 26 Nntp-Posting-Host: husc9.harvard.edu In article <1983@prcrs.prc.com> terryn@prcrs.prc.com (Terry Neely) writes: > > I am writing a Terminal Tool with the CommToolBox under System 6.0.x> >Are there any ftp-able samples that actually work with source laying around? >I have the CTB, tools, and sample source, but I would like to make sure I >have covered everything. There seem to be bugs in the Surfer example source >(ie Hlocks/Hunlocks), and the sample tool source uses hgetstate/hlock then >hsetstate but not hunlock. Is this a recommended way to handle memory? As for the Hlock/Hunlock story, it goes something like this: If a block of memory was locked by another function (say, the caller), and you lock it in your piece of code and then subsequently unlock it, the caller's lock is invalidated as well. More succintly, Hlock/Hunlock is not nestable. Your HUnlock at the end of your tool not only unlocks your previous Hlock but any previous Hlock that had been performed before the entrance to your tool. Thus, when using memory that you don't have complete control over (i.e., writing a tool or a driver or something like that), you use HGetState to get the previous settings of the lock bit, lock your handle, do whatever you want, and then just use HSetState with the previous setting to restore the state to exactly what it was before. Because the lock bit is one of these bits that's stored in HGetState, the HUnlock is not necessary. I'd love to see the tool when you're done. Good luck. -Edwin Aoki (aoki@husc9.harvard.edu)