| 80 | } |
| 81 | |
| 82 | ObjectPool *ObjectPool_New(uint64_t itemCap, uint itemSize, void (*fp)(void *)) { |
| 83 | ObjectPool *pool = rm_malloc(sizeof(ObjectPool)); |
| 84 | pool->itemCount = 0; |
| 85 | pool->itemSize = itemSize + HEADER_SIZE; // Add extra space to accommodate the item's header. |
| 86 | pool->blockCount = 0; |
| 87 | pool->blocks = NULL; |
| 88 | pool->deletedIdx = array_new(uint64_t, 128); |
| 89 | pool->destructor = fp; |
| 90 | _ObjectPool_AddBlocks(pool, ITEM_COUNT_TO_BLOCK_COUNT(itemCap)); |
| 91 | return pool; |
| 92 | } |
| 93 | |
| 94 | void *ObjectPool_NewItem(ObjectPool *pool) { |
| 95 | // Reuse a deleted item if one is available. |