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

  1. #ifndef __RWFIXMEM_H__
  2. #define __RWFIXMEM_H__
  3. pragma push_align_members(64);
  4.  
  5. /*
  6.  * RWFixedMemory: Very efficient fixed-length subsegment allocations.
  7.  *
  8.  * $Header:   E:/vcs/rw/fixmem.h_v   1.4   18 Feb 1992 09:54:22   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/fixmem.h_v  $
  23.  * 
  24.  *    Rev 1.4   18 Feb 1992 09:54:22   KEFFER
  25.  * 
  26.  *    Rev 1.3   28 Oct 1991 09:12:36   keffer
  27.  * Include path is now <rw/xxx.h>
  28.  * 
  29.  *    Rev 1.2   08 Sep 1991 18:39:30   keffer
  30.  * stddef.h now has STARTWRAP/ENDWRAP wrapper around it.
  31.  * 
  32.  *    Rev 1.1   28 Jul 1991 09:55:26   keffer
  33.  * Now includes <stddef.h>
  34.  * 
  35.  *    Rev 1.0   28 Jul 1991 08:05:36   keffer
  36.  * Initial revision.
  37.  *
  38.  */
  39.  
  40. #include "rw/defs.h"
  41. STARTWRAP
  42. #include <stddef.h>    /* Looking for size_t */
  43. ENDWRAP
  44.  
  45. #ifdef _Windows
  46. #  include <windows.h>
  47. #endif
  48.  
  49. class RWExport RWFixedMemory {
  50. #ifdef _Windows
  51.   HANDLE    hSegment;    // The handle of the segment we are managing (Windows only)
  52. #endif
  53.   char*        lpMem;        // Pointer to the memory block we are managing
  54.   size_t    slotSize;    // (Fixed) size of an allocation
  55.   size_t    _headerSize;    // Size of bitmap header 
  56.   unsigned    nSlots;        // Max number of outstanding allocations
  57.   unsigned    headerSize() const { return (unsigned)_headerSize; }
  58. public:
  59.   void*        allocate();        // Make an allocation; init() must have been called first
  60.   void        deallocate(void*);    // Return it
  61.   void        free();            // Return memory to system; do not call if allocations are outstanding!
  62.   void        init(size_t slotsize, unsigned nslots);    // Initialize self
  63.   RWBoolean    isEmpty() const;    // Returns FALSE if there are any outstanding allocations
  64.   RWBoolean    isValid() const
  65.     {return lpMem!=0;}
  66. };
  67.  
  68. pragma pop_align_members();
  69. #endif
  70.