home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!cs.utexas.edu!convex!constellation!apple!apple!NewsWatcher!user
- From: dowdy@apple.com (Tom Dowdy)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: 2 simple questions about locked blocks
- Message-ID: <dowdy-170792074347@90.10.20.25>
- Date: 17 Jul 92 14:47:51 GMT
- References: <1992Jul10.133017.3112@doug.cae.wisc.edu> <1992Jul10.205409.11486@newssun.med.miami.edu>
- Sender: usenet@Apple.COM
- Followup-To: comp.sys.mac.programmer
- Distribution: usa
- Organization: Apple Computer, Inc.
- Lines: 38
-
- In article <1992Jul10.205409.11486@newssun.med.miami.edu>,
- vvann@umbio.med.miami.edu (Vince Vann) wrote:
- > The memory manager does NOT keep track of how many times you lock or
- > unlock a handle. When you call HLock, the handle is locked immediately!
- > When you call HUnlock, the handle is unlocked immediately!!!
- >
- > However, this does not mean than in your source code you should HLock
- > a block 10 times, and then HUnlock it once (or vice versa).
- >
- > I suggest you always balance your calls to HLock/HUnlock. It is good
- > practice, it makes sense, and it will save you a lot of debugging headaches!
-
- Well, if you go into a routine with the handle locked and you unlock it,
- the routine that called you might be *very* surprised to see the handle
- that it locked suddenly become unlocked.
-
- When I'm writing large applications and I want to maintain "data hiding"
- within various parts of the application, I never call HUnlock, instead
- I do the following:
- HGetState(h, &flags);
- HLock(h);
- < fun stuff here >
- HSetState(h, flags);
-
- This works great, although it is a bit more expensive than your simple
- lock/unlock pairs. However, because there are *so* few times when
- locking a handle is really needed (DarkSide calls HLock 4 times, and
- they are all on resources) - the overhead of this code is fairly minor.
-
- When writing smaller and more localized applications (DarkSide comes to
- mind
- again), I usually just Lock/Unlock because I "know" what I'm doing.
-
- Tom Dowdy Internet: dowdy@apple.COM
- Apple Computer MS:81KS UUCP: {sun,voder,amdahl,decwrl}!apple!dowdy
- 20525 Mariani Ave AppleLink: DOWDY1
- Cupertino, CA 95014
- "The 'Ooh-Ah' Bird is so called because it lays square eggs."
-