home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 6.ddi / MWHC.006 / O1 < prev    next >
Encoding:
Text File  |  1992-06-07  |  2.4 KB  |  80 lines

  1. #ifndef __RWMEMPOOL_H__
  2. #define __RWMEMPOOL_H__
  3. pragma push_align_members(64);
  4.  
  5. /*
  6.  * RWMemoryPool: Manages small object pool via inheritance
  7.  *
  8.  * $Header:   E:/vcs/rw/mempool.h_v   1.7   18 Feb 1992 09:54:26   KEFFER  $
  9.  *
  10.  ****************************************************************************
  11.  *
  12.  * Rogue Wave 
  13.  * P.O. Box 2328
  14.  * Corvallis, OR 97339
  15.  * Voice: (503) 754-3010    FAX: (503) 757-6650
  16.  *
  17.  * Copyright (C) 1989, 1990, 1991. This software is subject to copyright 
  18.  * protection under the laws of the United States and other countries.
  19.  *
  20.  ***************************************************************************
  21.  *
  22.  * $Log:   E:/vcs/rw/mempool.h_v  $
  23.  * 
  24.  *    Rev 1.7   18 Feb 1992 09:54:26   KEFFER
  25.  * 
  26.  *    Rev 1.6   05 Nov 1991 14:24:50   keffer
  27.  * 
  28.  *    Rev 1.5   17 Oct 1991 09:13:00   keffer
  29.  * Changed include path to <rw/xxx.h>
  30.  * 
  31.  *    Rev 1.3   31 Aug 1991 20:40:28   keffer
  32.  * Now includes <stddef.h>, with a STARTWRAP wrapper
  33.  * 
  34.  *    Rev 1.1   24 Jul 1991 13:06:44   keffer
  35.  * Added pvcs keywords
  36.  *
  37.  */
  38.  
  39. /*
  40.  * This class maintains a pool of free memory allocations for small objects.
  41.  * Objects inheriting from it will be managed by it.  It can greatly improve
  42.  * the performance of objects that are rapidly allocated and deleted, such
  43.  * as nodes in a linked list or binary tree.  It can also help memory
  44.  * fragmentation.
  45.  *
  46.  * Two static variables affect its performance:
  47.  *
  48.  *  RWMAXPOOLS:        The number of different sizes managed.  The
  49.  *            default (5) will manage objects with sizes
  50.  *            from 1 to 10 bytes big.  Objects bigger than this
  51.  *             will be handled by the operating system.
  52.  *
  53.  *  RWPOOLSIZE:        The maximum number of objects retained within a size class.
  54.  *            Excess objects are returned to the operating system.
  55.  */
  56.  
  57. #ifndef __RWDEFS_H__
  58. #  include "rw/defs.h"
  59. #endif
  60. STARTWRAP
  61. #include <stddef.h>    /* Looking for size_t*/
  62. ENDWRAP
  63.  
  64. static const int RWPOOLSIZE = 5;
  65. static const int RWMAXPOOLS = 5;
  66.  
  67. class RWExport RWMemoryPool {
  68.   static void*        stash[RWMAXPOOLS][RWPOOLSIZE];    // The private stash
  69.   static short        nstash[RWMAXPOOLS];        // Number of free objects in each size class.
  70. public:
  71. #ifdef TCC_DELETE_SIZE_BUG
  72.   ~RWMemoryPool() { }    // Superfluous destructor required for Borland bug
  73. #endif
  74.   void            operator delete(void*, size_t);
  75.   void*            operator new(size_t);
  76. };
  77.  
  78. pragma pop_align_members();
  79. #endif
  80.