00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 #ifndef _MEMCACHE_HPP
00013 #define _MEMCACHE_HPP
00014 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 #include <cmath>
00030 #include "common_headers.hpp"
00031 
00032 #define MINPOW 5
00033 #define MAXPOW 22
00034 #define NLISTS MAXPOW-MINPOW+1
00035 
00036 class MemCache {
00037 public:
00041   MemCache(int cachesize);
00042 
00044   MemCache(int* cache, int cachesize);
00045 
00047   MemCache();
00048 
00052   ~MemCache();
00053 
00058   int* getMem(int chunksize);
00059 
00065   int* getMoreMem(int newsize, int* location, int oldsize);
00066 
00073   void freeMem(int* location, int memsize);
00074 
00078   void flushMem();
00079 
00080   int* getBegin();
00081   int* getEnd();
00082 
00083 private:
00089   int* getFromFree(int csize);
00090 
00091   int* begin;           
00092   int  size;            
00093   int* end;             
00094   int  intsize;         
00095   
00096   vector<int*> freelist[NLISTS]; 
00097   bool ourmem; 
00098 };
00099 
00100 #endif