lotus



previous page: 2.1) What is a handle? (Memory - Mac Programming)
  
page up: Mac Programming FAQ
  
next page: 2.3) How do I dispose of Handles? (Memory - Mac Programming)

2.2) When do I have to lock a Handle? (Memory - Mac Programming)




Description

This article is from the Mac Programming FAQ, by Jon Watte h+@austin.metrowerks.com with numerous contributions by others.

2.2) When do I have to lock a Handle? (Memory - Mac Programming)

The contents of a Handle may move, and when it does, the pointer your
handle is pointing to is changed to point to the new address so your
handle is always valid. The toolbox may call the memory manager to
allocate more memory pretty much anytime you call it (the toolbox) and
when memory is allocated, your handle may move in memory. Don't
dereference a handle into a pointer (or take the address of a field in a
record a handle is double-pointing to) and then call the toolbox and
expect the pointer to still be valid. The only way to ensure that the
pointer will still be valid is to call HLock on the handle to lock it.

Use HGetState and HSetState to save & restore the "locked" state of a
handle when you lock it.

 

Continue to:















TOP
previous page: 2.1) What is a handle? (Memory - Mac Programming)
  
page up: Mac Programming FAQ
  
next page: 2.3) How do I dispose of Handles? (Memory - Mac Programming)