| 80 | } |
| 81 | |
| 82 | Slot<T> allocSlot(Allocator* allocator) { |
| 83 | // try to allocate from free list |
| 84 | if (freeList_ != NULL_SLOT) { |
| 85 | return allocFromFreeList(); |
| 86 | } |
| 87 | |
| 88 | // try to allocate from last pool (other pools are full) |
| 89 | if (count_) { |
| 90 | auto slot = allocFromLastPool(); |
| 91 | if (slot) |
| 92 | return slot; |
| 93 | } |
| 94 | |
| 95 | // create a new pool and try again |
| 96 | auto pool = addPool(allocator); |
| 97 | if (!pool) |
| 98 | return {}; |
| 99 | |
| 100 | return allocFromLastPool(); |
| 101 | } |
| 102 | |
| 103 | void freeSlot(Slot<T> slot) { |
| 104 | reinterpret_cast<FreeSlot*>(slot.ptr())->next = freeList_; |