#include <pools.h>
Inheritance diagram for mem_pool< pool_type, max_handle >:
Public Types | |
typedef unsigned int | pool_handle |
Public Member Functions | |
void | pool_init (void) |
pool_handle | get_new_pool (void) |
Find the first free pool slot and allocate a pool. | |
void | release_pool (pool_handle handle) |
void * | GetMem (pool_handle handle, unsigned int num_bytes) |
void | pr (FILE *fp, pool_handle handle) |
Private Attributes | |
pool_type * | pools [max_handle] |
This allows the user to request a new memory pool (get_new_pool), allocate memory from this pool (GetMem) and delete the pool (release_pool).
The mem_pool class should be instantiated with a memory pool allocation object. For example:
mem_pool<big_block_pool, 128> big_pool;The constant argument (e.g., 128, in the above example), defines the maximum number of pools that can be active at once. Each pool has its own block chain and can be allocated and deallocated independently of the other pools.
The class functions are in-lined because some C++ compilers (notably Sun's) only support templates with in-lined class functions.
Definition at line 48 of file pools.h.
Member Typedef Documentation
|
Definition at line 54 of file pools.h. Referenced by mem_pool< big_block_pool, MAX_POOLS >::get_new_pool(). |
|
Find the first free pool slot and allocate a pool.
Definition at line 67 of file pools.h.
00068 { 00069 pool_handle handle; 00070 00071 for (handle = min_handle; handle < max_handle; handle++) { 00072 if (pools[handle] == NULL) { 00073 pools[handle] = new pool_type; 00074 break; 00075 } 00076 } 00077 if (handle > max_handle) { 00078 Fatal("big_pool::get_new_pool: no memory pools available"); 00079 } 00080 00081 return handle; 00082 } // get_new_pool |
|
Definition at line 95 of file pools.h.
00096 { 00097 void *mem; 00098 00099 mem = NULL; 00100 if (handle < max_handle && pools[ handle ] != NULL) { 00101 // mem = pools[ handle ]->MemAlloc( num_bytes ); 00102 mem = pools[ handle ]->pool_alloc( num_bytes ); 00103 } 00104 else { 00105 Fatal("big_pool::GetMem: bad pool handle"); 00106 } 00107 return mem; 00108 } // GetMem |
|
Definition at line 57 of file pools.h.
00058 { 00059 int i; 00060 00061 for (i = min_handle; i < max_handle; i++) { 00062 pools[ i ] = NULL; 00063 } 00064 } // pool_init |
|
Definition at line 110 of file pools.h.
|
|
Definition at line 84 of file pools.h.
|
|