karlg@runxtsa.runx.oz.au (Karl Goiser) (12/06/90)
Greetings, Quick question for you Gurus: If I swap the master pointers (?) of two Handles like so: VAR H1, H2: Handle; ... Ptemp:= H2^; H2^:= H1^; H1^:= H2^; ... will I hurt anybody or anything (including myself)? Thanks in advance! Karl
keith@Apple.COM (Keith Rollin) (12/10/90)
In article <2599@runxtsa.runx.oz.au> karlg@runxtsa.runx.oz.au (Karl Goiser) writes: >If I swap the master pointers (?) of two Handles like so: > >VAR > H1, H2: Handle; > >... > >Ptemp:= H2^; >H2^:= H1^; >H1^:= H2^; >... > >will I hurt anybody or anything (including myself)? Karl, I think that you may also have to munge with the "relative handle" in the block header. Take a look at figure 12 on page II-24. There it shows that the block header for relocatable blocks contain a reference to their master pointers. If you swap master pointers, then the master pointer that the relocatable block points to will not, in turn, point to that relocatable block. So why are you trying to do this? What is the need for swapping master pointers? As it notes on page II-24, "...your program shouldn't normally have to deal with block headers directly...". Also, the block header format has changed for 32-bit mode under 7.0, which means that any block header munging you do today will change tomorrow. -- ------------------------------------------------------------------------------ Keith Rollin --- Apple Computer, Inc. --- Developer Technical Support INTERNET: keith@apple.com UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith "Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions
russotto@eng.umd.edu (Matthew T. Russotto) (12/10/90)
In article <2599@runxtsa.runx.oz.au> karlg@runxtsa.runx.oz.au (Karl Goiser) writes: > >If I swap the master pointers (?) of two Handles like so: > >VAR > H1, H2: Handle; >... >Ptemp:= H2^; >H2^:= H1^; >H1^:= H2^; >... > >will I hurt anybody or anything (including myself)? Yes-- you could lose the flags byte under a 32-bit Memory manager, and other forms of heap corruption are probably also possible. -- Matthew T. Russotto russotto@eng.umd.edu russotto@wam.umd.edu .sig under construction, like the rest of this campus.
daven@svc.portal.com (12/10/90)
In article <2599@runxtsa.runx.oz.au> karlg@runxtsa.runx.oz.au (Karl Goiser) writes: >Quick question for you Gurus: > >If I swap the master pointers (?) of two Handles like so: > >VAR > H1, H2: Handle; > >... > >Ptemp:= H2^; >H2^:= H1^; >H1^:= H2^; >... > >will I hurt anybody or anything (including myself)? No! Don't even think of doing this! The reason why is that the Memory manager will likely become terribly confused if you do this. When the Mem Mgr creates a relocatable block, it places an 8 byte header in front of the block it gives you. This header contains a pointer back to the Master pointer. (Well, actually it's an offset to the Master pointer relative to the beginning of the heap zone) Changing the Master pointer would result in a situation where the Master pointer and the block's Relative pointer are no longer in agreement. A final point. Unless you know exactly who all has made copies of your handles, including whether the MacOS has or not, you risk having a copy made before you exchange the Master pointers, and then that copy will now point to the wrong relocatable block. -- ------------------------------------------------------------------------------- Dave Newman - Sofware Ventures | daven@svc.portal.com | AppleLink: D0025 Berkeley, CA (415) 644-3232 | AOL: MicroPhone | CIS: 76004,2161 -------------------------------------------------------------------------------