[futurebasic] Re: [FB] Handles and pointers

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 1999 : Group Archive : Group : All Groups

From: Paul Bruneau <paul_bruneau@...>
Date: Fri, 24 Sep 1999 07:25:59 -0400
Nice description once again, Rick!

The sloppy terminology that you describe is precisely the reason why it
took 3 of your fine descriptions before my brain got it all straightened
out. Each new one I hear just helps it get cemented in place.

I can actually remember the conversation where I asked a programmer
friend of mine "So is the handle the thing that points to the memory, or
is it the memory itself??" He couldn't answer.

PB

Rick Brown wrote:
> 
> Sylvain Guillemette wrote:
> 
> > Hi,
> >
> > I'm lost! (nothing unusual),
> >
> > Please help me!
> >
> > Here's my problems:
> >
> > 1)
> > How do i create a pointer to an handle created with NEWHANDLE ?
> > Is it just: HandlePtr& = @MyHandle ?
> 
> It's time to be careful with terminology here.  People often use the term "handle" when
> they really mean, "a relocatable block of memory which is referenced by a handle."  The
> _handle_ is a 4-byte long integer (always).  The _block_ it refers to can have any size.
> 
> Keeping that distinction in mind, the answer to (1) is yes, "HandlePtr& = @MyHandle&"
> gives you a pointer to the handle.  But remember that this is _not_ a pointer to the the
> data block.  To get a pointer to the block, use this:
> 
>   dataPtr& = PEEK LONG(MyHandle&)
> 
> or, equivalently:
> 
>   dataPtr& = [MyHandle&]
> 
> Once you've done this, beware of the fact that such a block can move to a different
> location in memory "without warning," and if it does, the value you stored into dataPtr&
> no longer points to the block.
> 
> >
> > 2)
> > How can i find out the size of the handle using just the pointer ? (with GETHANDLESIZE)
> 
> If "the pointer" is actually a pointer to the 4-byte handle, then you can get it like
> this:
> 
>   size& = GETHANDLESIZE([handlePtr&])
> 
> But if "the pointer" is a pointer to the data block--well, in that case I know of no way
> to get the handle's size.
> 
> BTW, "the size of the handle" is another example of that careless terminology (used by
> everybody including Apple).  They should technically say, "the size of the block which is
> referenced by the handle."
> 
> >
> > 3)
> > Also, by just using the pointer, how can i, for example, read the 12th byte in
> > the handle ?
> 
> Again, if it's a pointer to the _block_, do this:
> 
>   byte = PEEK(dataPtr& + 11)
> 
> (or safer, because it doesn't give the block a chance to move):
> 
>   byte = PEEK([MyHandle&] + 11)
> 
> >
> > 4)
> > How do i put, for example, 200 in the 12th byte of a handle ? (not using a pointer)
> 
>   POKE [MyHandle&] + 11, 200
> 
> >
> > Thanks!
> > Sylvain
> 
> Hope this helps.
> 
>  - Rick
> 
> --
> To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>