home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / gxxinc / xallocri.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-06  |  2.6 KB  |  113 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1989 Free Software Foundation
  4.     written by Doug Lea (dl@rocky.oswego.edu)
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor
  10. accepts responsibility to anyone for the consequences of using it
  11. or for whether it serves any particular purpose or works at all,
  12. unless he says so in writing.  Refer to the GNU CC General Public
  13. License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute
  16. GNU CC, but only under the conditions described in the
  17. GNU CC General Public License.   A copy of this license is
  18. supposed to have been given to you along with GNU CC so you
  19. can know your rights and responsibilities.  It should be in a
  20. file named COPYING.  Among other things, the copyright notice
  21. and this notice must be preserved on all copies.  
  22. */
  23.  
  24.  
  25. #ifndef _AllocRing_h
  26. #ifdef __GNUG__
  27. #pragma once
  28. #pragma interface
  29. #endif
  30. #define _AllocRing_h 1
  31.  
  32.  
  33. /*
  34.   An AllocRing holds the last n malloc'ed strings, reallocating/reusing 
  35.   one only when the queue wraps around. It thus guarantees that the
  36.   last n allocations are intact. It is useful for things like I/O
  37.   formatting where reasonable restrictions may be made about the
  38.   number of allowable live allocations before auto-deletion.
  39. */
  40.  
  41. /*
  42.  * dl: the typing for sizes in this entirely lib really sucks man!
  43.  * it really screws us on the atari where:
  44.  *    size_t != long != (necessarily) int != short
  45.  *
  46.  * yeah, yeah, i know i should'nt be complaining free software and all that
  47.  * jazz, but this is even asthetically displeasing: having a signed type for
  48.  * sizes firstly restricts the size (try int == 16 bits), and secondly
  49.  * it cuts out the possibility of catching sill error where the size
  50.  * is or becomes negative.
  51.  *
  52.  *  ++jrb
  53.  */
  54.  
  55. #ifdef atarist
  56.  
  57. class AllocRing
  58. {
  59.  
  60.   struct AllocQNode
  61.   {
  62.     void*  ptr;
  63.     size_t    sz;
  64.   };
  65.  
  66.   AllocQNode* nodes;
  67.   size_t      n;
  68.   size_t      current;
  69.  
  70.   long        find(void* p);
  71.  
  72. public:
  73.  
  74.               AllocRing(size_t max);
  75.              ~AllocRing();
  76.  
  77.   void*       alloc(size_t size);
  78.   int         contains(void* ptr);
  79.   void        clear();
  80.   void        free(void* p);
  81. };
  82.  
  83. #else
  84.  
  85. class AllocRing
  86. {
  87.  
  88.   struct AllocQNode
  89.   {
  90.     void*  ptr;
  91.     int    sz;
  92.   };
  93.  
  94.   AllocQNode* nodes;
  95.   int         n;
  96.   int         current;
  97.  
  98.   int         find(void* p);
  99.  
  100. public:
  101.  
  102.               AllocRing(int max);
  103.              ~AllocRing();
  104.  
  105.   void*       alloc(int size);
  106.   int         contains(void* ptr);
  107.   void        clear();
  108.   void        free(void* p);
  109. };
  110. #endif /* not atari */
  111.  
  112. #endif
  113.