home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / misc_src / cslib16b / include / csheap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-01  |  2.1 KB  |  82 lines

  1. /***********************************************************************
  2.  
  3.                                        CSA Library, Version 1.6.b 
  4.                                          Released: March 2nd 1995 
  5.  
  6.        HEAP class, for allocating memory in chunks of
  7.        about 2 Kb instead of allocating many small
  8.        blocks.
  9.  
  10.                                            Copyright(c) 1994,1995 
  11.                                                            Combis 
  12.                                                   The Netherlands 
  13. ***********************************************************************/
  14.  
  15. #ifndef __CSHEAP_H
  16. #define __CSHEAP_H
  17.  
  18. #include "stdio.h"
  19. #include "cstools.h"
  20. #include "cstypes.h"
  21.  
  22. class HEAP
  23. {
  24.    U16 size;    // Chunck size
  25.    U16 nr;    // Number of allocations in a page.
  26.    U16 rs;    // Real chunk size;
  27.    U16 pasi;    // Page size;
  28.    U32 nrbl;    // Number of Blocks allocated.
  29.    U16 is_open;
  30.  
  31.    void *np;    // Next page
  32.    void *fp;    // Chain of full pages.
  33.  
  34.    typedef struct
  35.    {
  36.      void *n;    // next page
  37.      void *p;    // prev page
  38.      void *e;    // empty chain
  39.      U16  count;// number available
  40.    } pahe;    // Page HEader
  41.  
  42.  
  43. protected:
  44.    void connect(void *l,void *r);
  45.    void *new_page(void);
  46.    void unchain(void *&chain,void *p);
  47.    void head_chain(void *&chain,void *p);
  48.    void zap2(void );
  49.  
  50. public:
  51.  
  52.    ~HEAP(void) { if (is_open) close(); }
  53.    HEAP(void)  { is_open=FALSE; fp=np=NULL; nrbl=0; size=0; }
  54.  
  55. ////////////////////// Compatibility functions //////////////////////////
  56.    void vfree(void *p) { free(p); }
  57.    void *vmalloc(void) { return malloc(); }
  58.  
  59.  
  60. ////////////////////// Init/Creation ////////////////////////////////////
  61.    void init(U16 s,U16 page_size=2048);
  62.  
  63. ////////////////////// Open/Close ///////////////////////////////////////
  64.    void close(void);
  65.    int    open(void);
  66.  
  67. ////////////////////// Malloc/Free //////////////////////////////////////
  68.    void free(void *);
  69.    void *malloc(void);
  70.  
  71.  
  72.    void empty(void );
  73.    void zap(void );
  74.    U32    blocks(void) { return nrbl; }
  75.    void report(FILE *fp,int sub);
  76.  
  77.  
  78. };
  79.  
  80.  
  81. #endif
  82.