[futurebasic] Re: Handles or Pointers?

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

From: Chris Stasny <staz@...>
Date: Mon, 15 Jun 1998 14:36:35 -0500
>Which one's better to work with? Creating and Destroying, at least?
>I have a program where I allocate 3 64k handles (using globals), work with
>them a little, and when I choose "quit" off my menu, I crash into macsbugs.
>What's funny is I've been through it with the debugger, and it doesn't
>crash when deallocating the handles, it crashes on the FN call itself?!?!
>I've only been able to consider the possibility that the allocating and
>playing with of handles are doing this; it never ever crashed before i
>tried using global handles.
>So my assumption is to instead allocate pointers, because I seem to never
>work with the actual handles I'm allocating anyway??? I'm always working
>with the pointer (ie. gPointer& = PEEK WORD(gHandle&))
>Or is it possible that i'll see the exact same crashes no matter what?
>And how do I work with pointers as compared to working with handles?
>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&)
>But I crash just when calling the FN that kills the handles; I don't even
>get one line into it...!
>So, are pointers better?!?

DISPOSEHANDLE could easily crash. Why and how depends on the version of the
system and the type of machine. A safer bet is to always use DEF DISPOSEH
which checks the validity of the handle in advance, and zeros it on exit.

If a cow laughed, would milk come out her nose?

-STAZ   ~)~

STAZ Software * 4387 Leisure Time Dr * Diamondhead, MS 39525
Orders: 800-348-2623      EMail http: //www.stazsoftware.com
  Tech: 228-255-7085             FAX: 228-255-7086