Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!jarthur!nntp-server.caltech.edu!toddpw From: toddpw@nntp-server.caltech.edu (Todd P. Whitesel) Newsgroups: comp.sys.apple2 Subject: Re: Handles Message-ID: <1990Dec22.083627.5994@nntp-server.caltech.edu> Date: 22 Dec 90 08:36:27 GMT References: <1198@dg.dg.com> <18830@netcom.UUCP> Organization: California Institute of Technology, Pasadena Lines: 22 zane@ddsw1.MCS.COM (Sameer Parekh) writes: > Why DO handles exist? Why can't one just use the pointers? >(I am learning programming now. . .) Handles are a concept that Apple came up with to deal with memory management on the Mac and the GS. The basic idea is that you allocate memory through the memory manager, and the memory manager returns a handle, which is actually a pointer to the memory manager's struct/record of info about the allocated block. The first element of the structure is a pointer to the current location of the memory block -- if the memory manager can't satisfy a request (or someone explicitly requests it) the memory manager will move or purge blocks in order to free up memory. When it moves a block, the memory manager changes the pointer that your handle points to, so you can still get at the block. If you need a pointer to the block, then you need to tell the memory manager to not move the block and dereference the handle to get a pointer to the block. (If the block gets purged, the pointer to the block is set to 0 -- this is called an 'empty handle'. Handles themselves cannot be 0 and represent an error condition.) Todd Whitesel toddpw @ tybalt.caltech.edu