home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / MiscKit / Headers / misckit / MiscObjectRecycler.h < prev    next >
Encoding:
Text File  |  1994-03-23  |  2.3 KB  |  51 lines

  1. //
  2. //    MiscObjectRecycler.h -- a category to speed up alloc/free of piddly objects
  3. //        Written by Don Yacktman Copyright (c) 1994 by Don Yacktman.
  4. //                Version 1.0.  All rights reserved.
  5. //
  6. //        This notice may not be removed from this source code.
  7. //
  8. //    This object is included in the MiscKit by permission from the author
  9. //    and its use is governed by the MiscKit license, found in the file
  10. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  11. //    for a list of all applicable permissions and restrictions.
  12. //
  13.  
  14. #import <appkit/appkit.h>
  15.  
  16. // This class came about because of the GKActorManager that I wrote aeons
  17. // ago (well, Summer 1993) for the GameKit.  The idea was that alloc'ing
  18. // and then freeing objects over and over was too time consuming for a
  19. // game, where sprites and such are coming in and out of scope rapidly.
  20. // So, to speed it up, why not keep the old objects around and re-init
  21. // them as needed?  I can keep them in Lists that are stored in a HashTable
  22. // with the class id as the key to the HashTable.  Well, it seems that the
  23. // idea is even more useful when dealing with things like MiscStrings
  24. // that come in and out of scope even more often.  Since only one manager
  25. // really makes sense, I only need one instance.  So why not use static
  26. // variables, and make it a category of the Object class itself?
  27.  
  28. // If you're interested in seeing the old code, check out the gamekit_future
  29. // package in pub/next/gamekit on ftp.byu.edu.  There are two major bugs in
  30. // it that I have now fixed, though.  I also changed all the names...
  31.  
  32. @interface Object(MiscObjectRecycler)
  33.  
  34. + recycler; // returns the List of useable objects for receiving class
  35.  
  36. // The next two grab recyclers for classes given the class object or name.
  37. + recyclerForClass:aClass;
  38. + recyclerForClassName:(const char *)className;
  39.  
  40. + newFromRecycler; // get an object from recycler and init it.
  41. + reInitObject:anObject; // to re-init, -init is called.  If that doesn't
  42.         // init all the instance variables or shouldn't be called twice,
  43.         // it's up to you to override this and get it right.'
  44. + firstInitObject:anObject;  // If the recycler was empty, we init a new
  45.         // object the first time.  Override this to do it differently than
  46.         // just by calling init.
  47. - recycle;    // a replacement for -free.  You could override -free to make
  48.         // it actually recycle objects, if you like.
  49.  
  50. @end
  51.