给 QueueItem 提供自定义的内存管理
| 55 | |
| 56 | // 给 QueueItem 提供自定义的内存管理 |
| 57 | void *operator new(size_t size) |
| 58 | { |
| 59 | if (_itemPool == nullptr) |
| 60 | { |
| 61 | _itemPool = (QueueItem*) new char[POOL_ITEM_SIZE * sizeof(QueueItem)]; |
| 62 | QueueItem *p = _itemPool; |
| 63 | for (; p < _itemPool + POOL_ITEM_SIZE - 1; ++ p) { |
| 64 | p->_next = p + 1; |
| 65 | } |
| 66 | p->_next = nullptr; |
| 67 | } |
| 68 | |
| 69 | QueueItem *p = _itemPool; |
| 70 | _itemPool = _itemPool->_next; |
| 71 | return p; |
| 72 | } |
| 73 | |
| 74 | void operator delete(void *ptr) |
| 75 | { |
nothing calls this directly
no outgoing calls
no test coverage detected