[comp.sys.apple2] Handles Re: Handle Dereferencing

zane@ddsw1.MCS.COM (Sameer Parekh) (12/22/90)

	Why DO handles exist?  Why can't one just use the pointers?
(I am learning programming now. . .)

-- 
zane@ddsw1.MCS.COM

dlyons@Apple.COM (David A. Lyons) (12/23/90)

In article <1990Dec22.041312.347@ddsw1.MCS.COM> zane@ddsw1.MCS.COM (Sameer Parekh) writes:
>
>	Why DO handles exist?  Why can't one just use the pointers?
>(I am learning programming now. . .)
>
>-- 
>zane@ddsw1.MCS.COM

Handles exist so that after you allocate lots of hunks of memory, dispose
of a lot of them, allocate more of different sizes, etc, you don't have
to be stuck with all the weird-sized "holes" between hunks.

By having handles, the Memory Manager can move many memory block around
to consolidate the free space into bigger chunks, and whoever allocated
those memory blocks can still get at them, because they have a handle.

(Each handle points to a "master pointer," which never moves.  The master
pointer *changes* when the block gets moved.)

Read the Memory Manager chapter in Toolbox Ref Volume 1!

-- 
David A. Lyons, Apple Computer, Inc.      |   DAL Systems
Apple II System Software Engineer         |   P.O. Box 875
America Online: Dave Lyons                |   Cupertino, CA 95015-0875
GEnie: D.LYONS2 or DAVE.LYONS         CompuServe: 72177,3233
Internet/BITNET:  dlyons@apple.com    UUCP:  ...!ames!apple!dlyons
   
My opinions are my own, not Apple's.

ericmcg@pnet91.cts.com (Eric Mcgillicuddy) (12/23/90)

Handles allow you to put the actual code anywhere in memory. The Handle also
tracks various attributes of the memory to which it holds the pointer, i.e.
who owns, what can be done to it, if it can be moved, etc. This allows a
certain amount of memory protection without the expense of hardware memory
management equipment, which is typical of Apple's design philosophy (not just
the Apple II either). 

Dereferencing a Handle in assembly is a bit ugly, but in C it is a piece of
cake. Don't worry about it too much, just pick "Programmer's Introduction to
the Apple IIGS". This book explains much of what you need to know about
programming.

BTW handles also allow you to move the actual code around in memory (if it can
be moved that is).

UUCP: bkj386!pnet91!ericmcg
INET: ericmcg@pnet91.cts.com