phil@mva.cs.liv.ac.uk (05/15/89)
I've started work on the most enormous Mac program I've ever written (which isn't hard 'cos I haven't written very many) and I'm wondering about the best way to write it. Basically the program is choc-a-bloc with resources - most PICTs, which I need to display, and probably "snd "s too. The program has a number of sections, which can be called in a sequence which is not known in advance, and each section needs various PICTs and snds. The question is this: Is it better to get handles to all of the resources that I will be using at the beginning of the program (they are all mostly purgeable resources) and then dispose of them at the end, or is it better only to Get them when the appropriate section starts, and to do a ReleaseResource on them when I'm through with that section. The trouble is that I got the impression from the Resource Manager section of IM that you should only do a Release on a resource that you're through with, and I don't know whether I am until I exit my program! I am therefor a little confused and would welcome advice from anyone who cares to give it. For information, the program is to be used by children - hence the large number of pictures and sounds, and I'm writing it using LSP 2.0, which is just _wonderous_ !!!!! (I just love that debugger!!) Thanks for your help! Phil Jimmieson, *************************************************** Computer Science Dept., * * Liverpool University, * JANET : PHIL@UK.AC.LIV.CS.MVA * Merseyside, England, * ARPA : PHIL%mva.cs.liv.ac.uk@cunyvm.cuny.edu * L69 3BX * * * * (UK) 051-794-3689 ***************************************************
trebor@biar.UUCP (Robert J Woodhead) (05/18/89)
In article <5455@mva.cs.liv.ac.uk> phil@mva.cs.liv.ac.uk writes: >Is it better to get handles to all of the resources that I will be using >at the beginning of the program (they are all mostly purgeable resources) >and then dispose of them at the end, or is it better only to Get them when >the appropriate section starts, and to do a ReleaseResource on them when >I'm through with that section. To an extent, you are asking the wrong question. First of all, call MoreMasters a bunch of times at the start of your program so that you have plenty of space for your master pointers. Then you can do one of two things: 1) Use something like GetResource to get handles to the resources you want at the start of the program and stick em in an array or structure for later use. Remember to SetResLoad(FALSE) before doing these calls so the actual data isn't loaded, and SetResLoad(TRUE) afterwards. 2) Call GetResource just before you want to use a particular resource. Define all these resources as purgeable. Then, once you have the handle to the resource, H, (via 1 or 2 above), do this: LoadResource(H); HNoPurge(H); HLock(H); .. do whatever you want with the resource data .. HUnlock(H); HPurge(H); If the resource is not in memory, LoadResource will load it, otherwise it will do nothing. HNoPurge and HLock make sure it stays in memory while you are using it, and that it doesn't get moved on you, so you can dereference the handle if you feel the need. When you are done, HUnlock and HPurge will return the status to the original, and if the memory manager needs space, it will move the block or purge it, in which case, the next time you need it, the LoadResource will load it again for you. Thus the system will manage things for you. Pick the approach that fits the program and your style. Read the resource manager sections of IM carefully. Good luck. -- Robert J Woodhead, Biar Games, Inc. !uunet!biar!trebor | trebor@biar.UUCP "The lamb will lie down with the lion, but the lamb won't get much sleep." -- Woody Allen.