Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!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.103638.4287@nntp-server.caltech.edu> Date: 22 Dec 90 10:36:38 GMT References: <1198@dg.dg.com> <18830@netcom.UUCP> Organization: California Institute of Technology, Pasadena Lines: 23 >zane@ddsw1.MCS.COM (Sameer Parekh) writes: >> Why DO handles exist? Why can't one just use the pointers? >>(I am learning programming now. . .) Heh.. the half screen lecture I just posted buries the real answer to your question -- it's so the memory manager can move blocks around without worrying about what you're doing. Here's how to politely use memory: If the block is going to be used a lot, allocate it as Fixed and Locked. Dereference the handle and use the pointer for whatever evil purposes. If the block is not going to be used a lot, allocate it without restrictions and either always reference it through the handle or call HLock(handle) before making and using a pointer to it and HUnlock(handle) afterwards. This way the block is always fixed &/or locked (I haven't bothered with purgable yet) while a pointer to it exists. If all you need is a handle, unlock it so the memory manager can move it around if the situation warrants. This is what Apple asks you to do and it helps the memory manager keep down the number of little pockets of wasted memory (i.e. it helps avoid "memory fragmentation"). Todd Whitesel toddpw @ tybalt.caltech.edu