home *** CD-ROM | disk | FTP | other *** search
- //
- // MiscObjectRecycler.h -- a category to speed up alloc/free of piddly objects
- // Written by Don Yacktman Copyright (c) 1994 by Don Yacktman.
- // Version 1.0. All rights reserved.
- //
- // This notice may not be removed from this source code.
- //
- // This object is included in the MiscKit by permission from the author
- // and its use is governed by the MiscKit license, found in the file
- // "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
- // for a list of all applicable permissions and restrictions.
- //
-
- #import <appkit/appkit.h>
-
- // This class came about because of the GKActorManager that I wrote aeons
- // ago (well, Summer 1993) for the GameKit. The idea was that alloc'ing
- // and then freeing objects over and over was too time consuming for a
- // game, where sprites and such are coming in and out of scope rapidly.
- // So, to speed it up, why not keep the old objects around and re-init
- // them as needed? I can keep them in Lists that are stored in a HashTable
- // with the class id as the key to the HashTable. Well, it seems that the
- // idea is even more useful when dealing with things like MiscStrings
- // that come in and out of scope even more often. Since only one manager
- // really makes sense, I only need one instance. So why not use static
- // variables, and make it a category of the Object class itself?
-
- // If you're interested in seeing the old code, check out the gamekit_future
- // package in pub/next/gamekit on ftp.byu.edu. There are two major bugs in
- // it that I have now fixed, though. I also changed all the names...
-
- @interface Object(MiscObjectRecycler)
-
- + recycler; // returns the List of useable objects for receiving class
-
- // The next two grab recyclers for classes given the class object or name.
- + recyclerForClass:aClass;
- + recyclerForClassName:(const char *)className;
-
- + newFromRecycler; // get an object from recycler and init it.
- + reInitObject:anObject; // to re-init, -init is called. If that doesn't
- // init all the instance variables or shouldn't be called twice,
- // it's up to you to override this and get it right.'
- + firstInitObject:anObject; // If the recycler was empty, we init a new
- // object the first time. Override this to do it differently than
- // just by calling init.
- - recycle; // a replacement for -free. You could override -free to make
- // it actually recycle objects, if you like.
-
- @end
-