home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!data.nas.nasa.gov!taligent!apple!mumbo.apple.com!gallant.apple.com!NewsWatcher!user
- From: nerm@apple.com (Dean Yu)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: handles and MoveHHi
- Message-ID: <nerm-140992103237@90.10.20.86>
- Date: 14 Sep 92 17:36:44 GMT
- References: <1992Sep13.161238.28426@welchgate.welch.jhu.edu> <D88-JWA.92Sep13193711@cyklop.nada.kth.se>
- Sender: news@gallant.apple.com
- Followup-To: comp.sys.mac.programmer
- Organization: Apple Computer, Inc.
- Lines: 43
-
- In article <D88-JWA.92Sep13193711@cyklop.nada.kth.se>,
- d88-jwa@cyklop.nada.kth.se (Jon W{tte) wrote:
- >
- > > francois@welchgate.welch.jhu.edu (Francois Schiettecatte) writes:
- >
- > - is there a real advantage to using MoveHHi before locking your
- > handles, I have not really seen much on that except that Think Reference
- > suggests that is *may* help in reducing heap fragmentation. Are there
- > any definite rules for using MoveHHi and caveat.
- >
- > MoveHHi is, uh, somewhat expensive since the toolbox
- > goes to a fair amount of trouble to move stuff out of
- > the way and move the handle HIGH up in the heap.
- >
- > If you're going to keep the handle locked for a long
- > time (i.e. a minute or more...) it's a very good idea,
- > but if you only lock the handle to pass it to a toolbox
- > routine, it's no idea. (Or rather, a bad idea)
- >
- > - Also when passing parameters in C is it better to use pointers or
- > handles. I guess the answer is really along the lines of it depends
- > on what you do with them afterwards, ie do you lock them, do you need to
- > allocate new memory, etc. Does anyone have any guidelines for this.
- >
- > Well, if it's a handle from the start, pass it as a handle
- > as far as possible, because you get more constrained when
- > you can't "do" anything with a handle. Also, if your function
- > takes a pointer, never assume that's a dereferenced handle.
- > RecoverHandle is EXPENSIVE! The reverse is also true; don't
- > pass the address of a pointer to something that wants a handle.
- >
-
- In addition to what Jon said, if you're using a handle for the sake of
- using a handle, and you keep it locked for the duration of your program's
- life, you might as well use a pointer and save yourself a dererference.
- This won't cost you much in terms of fragmentation, since pointers are
- created as low in the heap as possible. If you create all the pointers you
- need early in your program, your non-relocatable blocks should be neatly
- organized at the bottom of your heap.
-
- -- Dean Yu
- Blue Meanie, Negative Ethnic Role Model, etc.
- Apple Computer, Inc.
-