The running example below is the creation of a pool for scratch-space for the set-partition ADT: 1. Defining the pool and its accessors =================================== +++In p2mem/p2mem.C: List the pool in the P2MEM_pool_vec vector (for debugging pools): ----------------------------------------------------------------- p2mem_POOL_VEC_ENTRY(SP_scratch_pool); Declare the pool: ----------------- POOL_NODE SP_scratch_pool; Define the malloc/realloc functions for the pool: ------------------------------------------------- EXTERN PTR SP_Scratch_Malloc(INT size) { RETURN POOL_Salloc(&SP_scratch_pool,size); } EXTERN PTR SP_Scratch_Realloc(PTR ptr,INT old_size,INT new_size) { RETURN POOL_Srealloc(&SP_scratch_pool,ptr,old_size,new_size); } +++In p2mem/p2mem.H: Export the pool: --------------- EXTERN POOL_NODE SP_scratch_pool; Export the pool alloc/realloc functions: ---------------------------------------- EXTERN PTR SP_Scratch_Malloc(INT size); EXTERN PTR SP_Scratch_Realloc(PTR ptr,INT old_size,INT new_size); 2. Using the pool ============== Create the pool: ----------------- POOL_Create(&SP_scratch_pool,4,0); Reset the pool: ------------------- POOL_Sreset(&SP_scratch_pool); De-allocate the pool: -------------------- POOL_Delete(&SP_scratch_pool);