home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / mac / programm / 12959 < prev    next >
Encoding:
Internet Message Format  |  1992-07-23  |  2.2 KB

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