[futurebasic] Re: Handles or Pointers?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 1998 : Group Archive : Group : All Groups

From: Mel and Carol Patrick <mel@...>
Date: Sun, 14 Jun 1998 23:28:46 -0700
>Usually, I:
>  gameImg1& = FN NEWHANDLE _clear(65536)          'Rom(64k)
>  gameImg2& = FN NEWHANDLE _clear(65536)          'Rom(64k)
>  CharImg1& = FN NEWHANDLE _clear(65536)          'Char Rom(64k)
>get the pointers:
>  gameImg1Ptr& = PEEK LONG(gameImg1&)
>  gameImg2Ptr& = PEEK LONG(gameImg2&)
>  CharImg1Ptr& = PEEK LONG(CharImg1&)
>lock the handles(using HLOCK)
>write the data:
>      READ FILE #1,gameImg1Ptr&,size&
>unlock the handles(using HUNLOCK)
>kill the handles:
>  Oserr%=FN DISPOSHANDLE(CharImg1&)
>  Oserr%=FN DISPOSHANDLE(gameImg2&)
>  Oserr%=FN DISPOSHANDLE(gameImg1&)

My guess :

OSErr=FN HLOCK(gameImg1&):' lock down the handle so mem don't move
' Always a good idea to make sure you're not reading in more than the
handle size.
READ FILE #1,[gameImg1&],size&:' read into memory (gets a pointer from handle)
OSErr=FN HUNLOCK(gameImg1&):' unlock the block to allow memory to float
to get rid of the handles :

LONG IF gameImg1&:' did we get a handle
To get a pointer from a handle, ptr&=[gameImg1&] but lock the handle down
if you plan on reading or writing to it because Mr. Memory Manager can move
it on you.

You could also use DEF DISPOSEH(gameImg1&) to check for a null handle and
get rid of it rather than my short check above.

Good luck.

Mel Patrick - theWabbitGuy - mel@...