[comp.sys.mac.programmer] 32-bit Cleanliness

dank@calvin.usc.edu (Dan King) (01/08/91)

I've got a question on the Politically Correct way to dereference a
resource.

Example (using C-ish syntax):
I call GetResource(blah) to get a handle to the resource.  I then
Detach() it and HLock() it.  What should I do to dereference it?
Should I kill the upper 8 bits (I don't think so), should I
StripAddress it (TN212 says not, but who knows?), or should I just go
ahead and dereference it (Ptr x; x=*handle;)?  HELP!!!!

I've read the technote on being 32-bit clean and the technote on
StripAddress.  Neither really tells me (explicitly) what I need to do.
I believe that just dereferencing the handle without worrying about
the upper 8 bits will work, but doesn't the resource manager use those
for different states (like locked, purgeable, etc)?  Or do those go
away when you detach the handle?

Thanks for putting up with boring questions,
dank

russotto@eng.umd.edu (Matthew T. Russotto) (01/08/91)

In article <29193@usc> dank@calvin.usc.edu (Dan King) writes:
>
>I've got a question on the Politically Correct way to dereference a
>resource.
>
>Example (using C-ish syntax):
>I call GetResource(blah) to get a handle to the resource.  I then
>Detach() it and HLock() it.  What should I do to dereference it?
>Should I kill the upper 8 bits (I don't think so), should I
>StripAddress it (TN212 says not, but who knows?), or should I just go
>ahead and dereference it (Ptr x; x=*handle;)?  HELP!!!!

Handles should never need to be StripAddress()ed.  Go ahead and dereference it.
>
>I've read the technote on being 32-bit clean and the technote on
>StripAddress.  Neither really tells me (explicitly) what I need to do.
>I believe that just dereferencing the handle without worrying about
>the upper 8 bits will work, but doesn't the resource manager use those
>for different states (like locked, purgeable, etc)?  Or do those go
>away when you detach the handle?

Those things are in the master pointer, not the handle.  There are only a few
cases where you need to worry about this.  One is when comparing master 
pointers (i.e. *foohandle > *barhandle-- why one compares master pointers
I don't know...) .  Another is if you are on a machine with a 24 bit memory
manager running and you use SwapMMUMode to go to 32 bit mode.  All dereferences
of master pointers when you have the MMUMode at 32 bits must be StripAddressed

>
>Thanks for putting up with boring questions,
>dank


--
Matthew T. Russotto	russotto@eng.umd.edu	russotto@wam.umd.edu
     .sig under construction, like the rest of this campus.