Path: utzoo!attcan!telly!nebulus!contact!ben From: ben@contact.uucp (Ben Eng) Newsgroups: comp.sys.amiga.tech Subject: Re: resource tracking Summary: automatic resource reclamation Keywords: from Order comes CAOS Message-ID: <1990Feb4.213328.5099@contact.uucp> Date: 4 Feb 90 21:33:28 GMT References: <355.25C92297@weyr.FIDONET.ORG> Reply-To: ben@contact.UUCP (Ben Eng) Distribution: na Organization: Jet Penguin Lavatories Lines: 36 In article <355.25C92297@weyr.FIDONET.ORG> Jeff.Petkau@weyr.FIDONET.ORG (Jeff Petkau) writes: >or use intuition's Remember lists (automatically, that is.) For most >other things (screens, windows, filehandles, locks, libraries, >fonts...) keep a list of something like > > struct FunkyRemember { > void (*CloseFunc)(); /* the function to close this object */ > long Arg; /* the argument to pass closefunc */ > struct FunkyRemember *Next; > }; > >Now, say you call OpenScreen(). OpenScreen will create a new >FunkyRemember with CloseFunc=CloseScreen, Arg=the screen pointer and >link it into the list kept in your task structure. It is not quite as trivial as it sounds. Some resources such as Windows are dependent upon other resources (ie. a Screen) being already allocated. If you don't deallocate the resources in the correct order, things will blow up miserably. Many Intuition type resources will require special coding to handle this anyway. General-purpose resource tracking is great if you want to be able to kill a program, or if your program only deallocates its resources when it exits. Half the time, a programmer will probably find himself dynamically allocating a resource and returning it to the system as soon as the program is finished with it. The latter case would require the extra code anyway. Ben -- Ben Eng | ben@contact.uucp _or_ ben@ziebmef.mef.org 150 Beverley St. Apt #1L | Bix: jetpen ^^^-down for repair? Toronto, Ontario M5T 1Y6 | UofT Engineering Science: engb@ecf.toronto.edu _-_-_-_-_-_-_-_-_-_-_-_-_| Phone: (416)-979-7885, (416)-979-8761