gv9b2c9z@umiami.ir.miami.edu (Ordinary Man) (01/31/91)
Is it bad programming practice to double dereference a handle to a record (with linked lists in mind)? Is there a better way to do it without sacrificing a lot of time spent implementing it? I've tried linked lists both ways (with all pointers and with all handles). Right now I'm implementing it with all handles. I don't notice any speed difference that's significant so is it better to derefernce the handle twice or to set it to a pointer and then use that pointer? Let me illustrate: type listHand=^listPtr; listPtr=^list; list=record item:whatever; next:listHand; end; var theList:listHand; temp:listPtr; Do I say this: HLock(Handle(theList)); temp:=theList^; temp^.item:=whatever; ... or this: HLock(Handle(theList)); theList^^.item:=whatever; ... Or does it matter? Thanks in advance, ==Dan -- /-------------------------------------------------------------------------\ | Dan Weisman - University of Miami - Florida | || || || || | |--------------------------------------------------| || || ||\ /|| | | INTERNET -----> gv9b2c9z@umiami.IR.Miami.edu | || || || | || | | BITNET -----> gv9b2c9z@umiami | ||||||| || | || | |-------------------------------------------------------------------------| | "...bows it's head and prays to the mother of all machines." | \_________________________________________________________________________/
d88-jwa@dront.nada.kth.se (Jon W{tte) (02/02/91)
In article <> gv9b2c9z@umiami.ir.miami.edu (Ordinary Man) writes: >Is it bad programming practice to double dereference a handle to a record No, if it's only an assignment, I prefer this way. > HLock(Handle(theList)); > temp:=theList^; > temp^.item:=whatever; > HLock(Handle(theList)); > theList^^.item:=whatever; >Or does it matter? Not by much. If you don't like temp variables cluttering the declarations, you know what way to go... (Oh, and you mught be tempted to use the dereferenced handle later if it's hanging around in a pointer...) btw, you don't have to lock the handle if all you do with it is assignment, AND THE R.H.S. EXPRESSION DOESN'T MOVE MEMORY. Floating-point moves memory, as does trap calls. Simple math doesn't move memory. i.e. WindowRecord * * myWHandle = NewHandle ( sizeof ( WindowRecord ) ) ; /* Error checking &c ... */ * * myWHandle = * thePort ; /* This is legal without locking the handle ! */ >Thanks in advance, You're welcome, h+ :::::::: Jon W{tte, Stockholm, Sweden, h+@nada.kth.se :::::::: "The IM-IV file manager chapter documents zillions of calls, all of which seem to do almost the same thing and none of which seem to do what I want them to do." -- Juri Munkki (jmunkki@hut.fi) in comp.sys.mac.programmer