home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__inc / xallocri.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-23  |  2.6 KB  |  108 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 the GNU C++ Library.  This library is free
  7. software; you can redistribute it and/or modify it under the terms of
  8. the GNU Library General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  This library is distributed in the hope
  11. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE.  See the GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18.  
  19.  
  20. #ifndef _AllocRing_h
  21. #ifdef __GNUG__
  22. #pragma once
  23. #pragma interface
  24. #endif
  25. #define _AllocRing_h 1
  26.  
  27.  
  28. /*
  29.   An AllocRing holds the last n malloc'ed strings, reallocating/reusing 
  30.   one only when the queue wraps around. It thus guarantees that the
  31.   last n allocations are intact. It is useful for things like I/O
  32.   formatting where reasonable restrictions may be made about the
  33.   number of allowable live allocations before auto-deletion.
  34. */
  35.  
  36. /*
  37.  * dl: the typing for sizes in this entirely lib really sucks man!
  38.  * it really screws us on the atari where:
  39.  *    size_t != long != (necessarily) int != short
  40.  *
  41.  * yeah, yeah, i know i should'nt be complaining free software and all that
  42.  * jazz, but this is even asthetically displeasing: having a signed type for
  43.  * sizes firstly restricts the size (try int == 16 bits), and secondly
  44.  * it cuts out the possibility of catching sill error where the size
  45.  * is or becomes negative.
  46.  *
  47.  *  ++jrb
  48.  */
  49.  
  50. #ifdef atarist
  51.  
  52. class AllocRing
  53. {
  54.  
  55.   struct AllocQNode
  56.   {
  57.     void*  ptr;
  58.     size_t    sz;
  59.   };
  60.  
  61.   AllocQNode* nodes;
  62.   size_t      n;
  63.   size_t      current;
  64.  
  65.   long        find(void* p);
  66.  
  67. public:
  68.  
  69.               AllocRing(size_t max);
  70.              ~AllocRing();
  71.  
  72.   void*       alloc(size_t size);
  73.   int         contains(void* ptr);
  74.   void        clear();
  75.   void        free(void* p);
  76. };
  77.  
  78. #else
  79.  
  80. class AllocRing
  81. {
  82.  
  83.   struct AllocQNode
  84.   {
  85.     void*  ptr;
  86.     int    sz;
  87.   };
  88.  
  89.   AllocQNode* nodes;
  90.   int         n;
  91.   int         current;
  92.  
  93.   int         find(void* p);
  94.  
  95. public:
  96.  
  97.               AllocRing(int max);
  98.              ~AllocRing();
  99.  
  100.   void*       alloc(int size);
  101.   int         contains(void* ptr);
  102.   void        clear();
  103.   void        free(void* p);
  104. };
  105. #endif /* not atari */
  106.  
  107. #endif
  108.