[futurebasic] Re: [FB] Handles & Pointers

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

From: Jay Reeve <jktr@...>
Date: Fri, 25 Jun 99 20:20:43 -0500
>I have always been a bit uncertain about handles and how they are
>dereferenced, so I made up the following chart.
>I would appreciate any comments changed, added or deleted.Thanks in
>advance.
>
<snip>

Stewart,

You're almost there. Let me try a little different way.

myDataHandle&    holds the address of 

myDataPointer&   which holds the current location of

12300            my data.


myDataHandle&    will never change, because the _location_
                 of myDataPointer& will not change.

myDataPointer&   may change, because it holds the current
                 location of my data, which can be moved.

12300            doesn't change (unless I change it), but 
                 it can be relocated as needed.

Therefore,

[myDataHandle&]  always gives the current _value_ of
                 myDataPointer&, which is the _location_ of my data.

[myDataPointer&] will yield the first 4 bytes of my data, IFF the 
                 location of my data has not changed since getting
                 myDataPointer& from myDataHandle&.

{{myDataHandle&]] always gives the first 4 bytes of my data, because 
                 it peeks the _current value_ of myDataPointer&.

To borrow an analogy I read somewhere (sorry, I don't remember where), 
assume your data is a car in a parking lot with numbered stalls. When the 
attendant puts your Jag in a stall, he records the stall number on a 
master list. He gives you a tag with the number 22 to put in your pocket, 
because he recorded the stall number where your car is parked on line 22 
of the master list.

That tag is a handle to your car. It tells where to look to find the 
current location of your car. If the attendant takes your Jag out for a 
ride and parks it in a different stall when he returns, he will update 
the master list, recording a different stall number on line 22. 

When you return hours later, all of the attendants and all of their 
buddies have taken your Jag out for a ride, and parked it in a different 
stall each time. But they have always recorded the current location on 
line 22 of the list, so all they have to do to retrieve your car is look 
at line 22 and see what stall it is in.

However, if the attendant you are talking to remembers putting your Jag 
in stall #123 when _he_ returned it, but doesn't realize someone else has 
moved it since then, he has an invalid pointer to your car. If he goes to 
get your car without checking the list, he may bring you the wrong car, 
or find no car there at all. He will have to ask for your handle (22) so 
he can look at the list (dereference the handle) to find the new pointer 
so he can deliver your car.

The next time you park there, you might pay the attendant to put the keys 
in his pocket and swear on his mother's virtue that he will not allow the 
car to be moved. That's called locking the handle. The number recorded on 
the master list won't change.

Or, you might pursuade him to let you park the car yourself, memorize the 
stall number, and put the keys in your own pocket, bypassing the master 
list entirely. That's allocating a pointer. 

However, in either case, if the boss comes in and orders all the cars 
moved off of that level so new stripes can be painted, your car is going 
to really complicate the process--the stripe painters may not be able to 
do their job. So if you own the parking lot, it's to your advantage to 
have the cars moveable and use a master list to keep track.

Once you understand that the pointer tells you where to look _right_now_ 
for your data, and a handle tells you where the pointer is, you've got it 
made.

Good luck. I hope that helps.

 0"0
 =J= a  y
  "