Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

blockpool.h

Go to the documentation of this file.
00001 
00002 #ifndef _BLOCKPOOL_H_
00003 #define _BLOCKPOOL_H_
00004 
00034 
00035 
00036 #include <assert.h>
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039 
00065 
00066 class block_pool {
00067 public: // typedefs and variables
00070   typedef enum { one_kay = 1024,
00071                  page_size = (4 * one_kay),  /* 4 Kb */
00072                  max_block_multiple = 256,   /* 1 Mb */
00073                  last_enum
00074                } bogus;
00075 
00077   typedef struct block_chain_struct {
00079     void *block;
00080 
00082     unsigned int bytes_used;
00083 
00085     unsigned int block_size;
00086        
00088     block_chain_struct *next_block;
00089   } block_chain;
00090 
00091 private:
00093   static unsigned int alloc_gran;
00094 
00096   static block_chain *block_list_start; 
00097 
00099   static block_chain *current_block;    
00100 
00101 
00102 private: // class functions
00103   block_chain *new_block( unsigned int block_size );
00104   void *add_block( unsigned int block_size );
00105   void init_pool(void);
00106 
00107 
00108 protected:
00128   virtual void *MemAlloc( unsigned int n_bytes )
00129   {
00130     void *rtn = calloc( n_bytes, 1 );
00131     return rtn;
00132   }
00136   virtual void MemFree( void *addr )
00137   {
00138     free( addr );
00139   }
00140 
00141 
00142 public: // class functions
00145   block_pool(void) {}
00146 
00147   void free_pool(void);
00148   void *pool_alloc( unsigned int block_size );
00149   void print_block_pool_info( FILE *fp = stdout );
00150 
00151 }; // class block_pool
00152 
00153 
00154 
00155 /* Macros for block_chain pointers */
00156 
00158 #define Chain_block(p)            ((p)->block)
00159 
00161 #define Chain_bytes_used(p)       ((p)->bytes_used)
00162 
00164 #define Chain_block_size(p)       ((p)->block_size)
00165 
00167 #define Chain_next(p)             ((p)->next_block)
00168 
00169 
00170 #endif

Generated at Tue May 27 21:56:16 2003 for Wavelet compression, determinism and time series forecasting by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001