// // Basic Summary: pool memory allocation // // Include file for pool definition // // Copyright: // // Copyright 1993 Ron Burback // Copyright 1993 Objects Plus // All rights reserved // // Description: // // // Data elemnents: // There are two private struct defined for this class. // One is a linked list of avaiable elements ready to allocate - chunks // The other is a linked list of pools that have already been allocated // The variable TheHead keeps track of the available list // The variable ThePools keeps track of the pools // // // Methods: // // The methods are // pool(unsigned int size); - standard constructor, size of an element // ~pool(); - standard disctructor // free(void * p) - return a chunk to the pool // alloc() - allocate a chunk, grow if necessary // // static Boolean test(); = quality assurance test // #ifndef _OP_POOL #define _OP_POOL // Macro definitions: // just one, the number of elements that we want to allocate in each pool #define POOL_NUMBER_ELEMENTS 100 // // // Class definition: // // pool // class pool { private: struct chunk { chunk * next ;} ; struct pools { pools * next ; char * storage ; } ; const unsigned ElementSize ; chunk * TheHead ; pools * ThePools ; pool (pool&); // copy protected void operator= (pool&) ; // copy protected void grow() ; public: static char * version ; pool(unsigned int size); ~pool(); void * alloc() ; void free(void * element) ; static Boolean test(); }; #endif