Path: utzoo!attcan!uunet!samsung!zaphod.mps.ohio-state.edu!usc!apple!portal!cup.portal.com!ts From: ts@cup.portal.com (Tim W Smith) Newsgroups: comp.sys.mac.programmer Subject: Re: NewHandle(0L) ? Message-ID: <35053@cup.portal.com> Date: 20 Oct 90 03:24:19 GMT References: <32600007@inmet> <1990Oct19.151254.8197@ux1.cso.uiuc.edu> Organization: The Portal System (TM) Lines: 34 < Why call a handle up before you need to? If you If I'm going the be appending some dymanically calculated things to a list, I do something like this: if ( myHandle == 0 ) { myHandle = NewHandle(0); mySize = 0; } else mySize = SizeHandle( myHandle ); for ( blah blah ) while ( blah blah ) if ( blah blah ) { SetHandleSize( myHandle, mySize + whatever ); mySize += whatever; append the data } (I'm doing this from memory, so I might have the names of the handle manipulation traps wrong). By using the 0 size handle, we get rid of a special case in the loop. This makes the loop simpler (we don't have so many levels of nesting), and it makes the code more efficient (we don't have to check for myHandle being 0 each time through the loop). In general, whenever I need a list whose size is not known in advance, I like to start with a zero length handle. Tim Smith