00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef MF_MEMPOOL_H
00028 #define MF_MEMPOOL_H
00029
00030 #ifndef NULL
00031 const int NULL=0;
00032
00033 #endif
00034
00035 #include <iostream>
00036
00038
00043 class memnode{
00044 friend class mempool;
00045 friend class strstack;
00046 char *block;
00047 memnode *next;
00048 };
00049
00050
00052
00059 class mempool{
00060 int block_size;
00061 int item_size;
00062 int true_size;
00063 memnode* block_list;
00064 char* free_list;
00065 int entries;
00066 int blocknum;
00067 public:
00068
00070 mempool(int is, int bs);
00071
00073 ~mempool();
00074
00076 void map(std::ostream& co);
00077
00079 char *allocate();
00080
00082 int free(char* addr);
00083
00085 void stat();
00086
00088
00090 int used(){return blocknum * (true_size + 8);}
00091
00093 int wasted(){return used()-(entries * item_size);}
00094 };
00095
00097
00105 class strstack{
00106 memnode* list;
00107 int size;
00108 int idx;
00109 int waste;
00110 int memory;
00111 int entries;
00112 int blocknum;
00113
00114 public:
00115
00116 strstack(int bs=1000);
00117
00118 ~strstack();
00119
00120 const char *push(const char *s);
00121
00122 const char *pop();
00123
00124 const char *top();
00125
00126 void stat();
00127
00128 int used(){return memory;}
00129
00130 int wasted(){return waste;}
00131
00132 };
00133
00134
00136
00145 class storage{
00146 mempool **poolset;
00147 int setsize;
00148 int poolsize;
00149 int newmemory;
00150 int newcalls;
00151 public:
00152
00154 storage(int maxsize,int blocksize);
00155
00157 ~storage();
00158
00159
00160
00162 char *allocate(int size);
00163
00165 char *reallocate(char *oldptr,int oldsize,int newsize);
00166
00168 int free(char *addr,int size=0);
00169
00171 void stat();
00172 };
00173
00174 #endif