Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!ucbvax!bloom-beacon!eru!hagbard!sunic!news.funet.fi!cc.tut.fi!cc.tut.fi!n67786 From: n67786@lehtori.tut.fi (Nieminen Tero) Newsgroups: comp.sys.mac.programmer Subject: Re: Linked Lists: Handles or Pointers? Message-ID: Date: 26 Jan 91 17:52:02 GMT References: <1991Jan23.002212.7648@umiami.ir.miami.edu> <1991Jan24.203150.24546@ux1.cso.uiuc.edu> Sender: n67786@cc.tut.fi (Nieminen Tero) Organization: Tampere Univ. of Technology, Finland. Lines: 39 In-Reply-To: ml27192@uxa.cso.uiuc.edu's message of 24 Jan 91 20:31:50 GMT In article <1991Jan24.203150.24546@ux1.cso.uiuc.edu> ml27192@uxa.cso.uiuc.edu (lanett mark) writes: gross@umiami.ir.miami.edu (Mondo) writes: >Okay folks, here's yer big chance to solve a silly little argument for >three of us novice Mac programmers. >If you want to create a linked list, do you have to: > a) Use a handle to the head node only and use pointers > for the rest of the list (Problem we see: the Memory > Manager will compact the heap and make all those ptrs invalid.) If you use pointers and allocate structures with new then they are "locked" and will not be moved by the memory manager. Handles are for your memory conveniece only. Indeed pointers cannot be moved during program execution an thus they will stay valid all the time. But handles are not only for convinience only! It's wise to remember how jealous the system is when it comes to allocating a pointer. To minimize further heap fragmentation the system pursues all possible means to get the pointer allocated as low in the heap as possible. This also means compacting the memory so that handles are moved upwards to make room for the pointer. And there lies the speed penalty. If you opt for using handles the allocating process is significantly faster and there is less risk of fragmented heap. I remember testing pointer vs. handle allocation speed some time ago and a difference of order 5 to 10 were common. The test allocated several thousand variable size blocks and in case of the handles even locked them at place and dereferenced the handle. Still handles proved to be 5 times faster than pointers. Now that may or may not be significan in your program, but I'd advice making tests before deciding if in doubt. Mark Lanett -- Tero Nieminen Tampere University of Technology n67786@cc.tut.fi Tampere, Finland, Europe