| 1 |
#ifndef BLT_POOL_H |
| 2 |
#define BLT_POOL_H |
| 3 |
|
| 4 |
typedef struct Blt_PoolChainStruct { |
| 5 |
struct Blt_PoolChainStruct *nextPtr; |
| 6 |
} Blt_PoolChain; |
| 7 |
|
| 8 |
#define BLT_STRING_ITEMS 0 |
| 9 |
#define BLT_FIXED_SIZE_ITEMS 1 |
| 10 |
#define BLT_VARIABLE_SIZE_ITEMS 2 |
| 11 |
|
| 12 |
typedef struct Blt_PoolStruct *Blt_Pool; |
| 13 |
|
| 14 |
typedef void *(Blt_PoolAllocProc) _ANSI_ARGS_((Blt_Pool pool, size_t size)); |
| 15 |
typedef void (Blt_PoolFreeProc) _ANSI_ARGS_((Blt_Pool pool, void *item)); |
| 16 |
|
| 17 |
struct Blt_PoolStruct { |
| 18 |
Blt_PoolChain *headPtr; |
| 19 |
Blt_PoolChain *freePtr; |
| 20 |
|
| 21 |
size_t poolSize; |
| 22 |
size_t itemSize; |
| 23 |
size_t bytesLeft; |
| 24 |
size_t waste; |
| 25 |
|
| 26 |
Blt_PoolAllocProc *allocProc; |
| 27 |
Blt_PoolFreeProc *freeProc; |
| 28 |
}; |
| 29 |
|
| 30 |
EXTERN Blt_Pool Blt_PoolCreate _ANSI_ARGS_((int type)); |
| 31 |
EXTERN void Blt_PoolDestroy _ANSI_ARGS_((Blt_Pool pool)); |
| 32 |
|
| 33 |
#define Blt_PoolAllocItem(poolPtr, n) (*((poolPtr)->allocProc))(poolPtr, n) |
| 34 |
#define Blt_PoolFreeItem(poolPtr, item) (*((poolPtr)->freeProc))(poolPtr, item) |
| 35 |
|
| 36 |
#endif |