home *** CD-ROM | disk | FTP | other *** search
/ Computer Panoráma / computer_panorama_1997-12-hibas.iso / SHARE / GRAPH / PTC051.ZIP / SRC / MANAGER.H < prev    next >
C/C++ Source or Header  |  1997-08-20  |  2KB  |  82 lines

  1. ////////////////////
  2. // Memory manager //
  3. ////////////////////
  4.  
  5. #ifndef __MANAGER_H
  6. #define __MANAGER_H
  7.  
  8. #include "misc.h"
  9. #include "list.h"
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. class MemoryManager
  17. {
  18.     // friend classes
  19.     friend class MemoryBlock;
  20.  
  21.     public:
  22.  
  23.         // setup
  24.         MemoryManager();
  25.         MemoryManager(void *memory,uint size);
  26.         ~MemoryManager();
  27.  
  28.         // intialize and close
  29.         int Init(void *memory,uint size);
  30.         void Close();
  31.  
  32.         // interface
  33.         int Compact();
  34.  
  35.         // information
  36.         int GetSize();
  37.         int GetFree();
  38.  
  39.         // object status
  40.         int ok() const;
  41.  
  42.     private:
  43.  
  44.         // memory block
  45.         struct BLOCK
  46.         {
  47.             MemoryBlock *owner;          // owner object
  48.             void *address;               // address of memory
  49.             uint size;                   // size of memory
  50.             int count;                   // lock count
  51.         };
  52.  
  53.         // block manipulation
  54.         BLOCK* RequestBlock(MemoryBlock &owner,uint size,int managed=1);
  55.         void* LockBlock(BLOCK *block);
  56.         void UnlockBlock(BLOCK *block);
  57.         int ResizeBlock(BLOCK *block);
  58.         void FreeBlock(BLOCK *block);
  59.  
  60.         // list of standalone memory blocks                        
  61.         List<BLOCK> StandaloneList;                                // is this sorta tracking necessary?
  62.  
  63.         // list of managed memory blocks
  64.         List<BLOCK> BlockList;
  65.  
  66.         // list of free memory blocks
  67.         List<BLOCK> FreeBlockList;
  68.  
  69.         // memory to be managed
  70.         void *Memory;
  71.         uint MemorySize;
  72. };
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. #endif