NGSolve
4.9
|
00001 #ifndef FILE_BLOCKALLOC 00002 #define FILE_BLOCKALLOC 00003 00004 /**************************************************************************/ 00005 /* File: blockalloc.hpp */ 00006 /* Author: Joachim Schoeberl */ 00007 /* Date: 19. Apr. 2000 */ 00008 /**************************************************************************/ 00009 00010 namespace ngstd 00011 { 00012 00018 class BlockAllocator 00019 { 00021 unsigned int size; 00023 unsigned int blocks; 00025 void * freelist; 00027 Array<char*> bablocks; 00029 int nels; 00030 public: 00032 BlockAllocator (unsigned int asize, unsigned int ablocks = 100); 00034 ~BlockAllocator (); 00035 00037 void * Alloc (); 00038 /* 00039 { 00040 nels++; 00041 if (!freelist) 00042 Alloc2 (); 00043 00044 void * p = freelist; 00045 freelist = *(void**)freelist; 00046 return p; 00047 } 00048 */ 00049 00050 00052 void Free (void * p); 00053 /* 00054 { 00055 nels--; 00056 *(void**)p = freelist; 00057 freelist = p; 00058 } 00059 */ 00060 00062 int NumElements () { return nels; } 00063 00064 void Print (ostream * ost) const; 00065 private: 00066 void * Alloc2 (); 00067 }; 00068 00069 00070 } 00071 00072 #endif