Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!sdd.hp.com!elroy.jpl.nasa.gov!usc!jarthur!wilkins From: wilkins@jarthur.Claremont.EDU (Mark Wilkins) Newsgroups: comp.sys.mac.programmer Subject: Re: StripAddress() question Message-ID: <9697@jarthur.Claremont.EDU> Date: 19 Nov 90 17:47:21 GMT References: <90323.102417CXT105@psuvm.psu.edu> Organization: Harvey Mudd College, Claremont, CA 91711 Lines: 50 In article <90323.102417CXT105@psuvm.psu.edu> CXT105@psuvm.psu.edu (Christopher Tate) writes: >Do I need to call StripAddress() in the following situation? Here's the >relevant code: > >Handle myHand; >unsigned char *myPtr; > >myHand = NewHandle(AMOUNT); >HLock(myHand); >myPtr = StripAddress(*myHand); /* <-- do I need to do this? */ >/* Now, put stuff into the block, using and incrementing myPtr */ > >Do I need to call StripAddress(*myHand) to make sure I get a valid >pointer into the block? NO, you do not, and in a tight loop you shouldn't. Here's my logic: myHand points to a master pointer like this when running in 24-bit mode: xxxx xxxx 0000 0000 0000 0000 0000 0000 where the x's are mem. manager flags and the 0's are address data. In 32-bit mode the master pointer looks like this: 0000 0000 0000 0000 0000 0000 0000 0000 If you make a copy of the master pointer and increment it by two, you get the following: xxxx xxxx 0000 0000 0000 0000 0000 0010 (24-bit) 0000 0000 0000 0000 0000 0000 0000 0010 (32-bit) However, the 24-bit memory manager ignores the top 8 bits, whereas the 32-bit memory manager does not. So you get the right address when you access your incremented pointer. The case where StripAddress is needed is where you could be running in 24-bit mode and you call SwapMMUMode to set the addressing to 32-bit for a short time, as is necessary when accessing PixMap data directly. In that case, you need to make sure that the address is stripped before switching, because if it is not, the system will bus error when it tries to evaluate the flags as address bits. -- Mark Wilkins -- ******* "Freedom is a road seldom traveled by the multitude!" ********** *-----------------------------------------------------------------------------* * Mark R. Wilkins wilkins@jarthur.claremont.edu {uunet}!jarthur!wilkins * ****** MARK.WILKINS on AppleLink ****** MWilkins on America Online ******