MCPcopy Create free account
hub / github.com/EricPengShuai/Interview / operator new

Method operator new

practice/itemPool.cpp:57–72  ·  view source on GitHub ↗

给 QueueItem 提供自定义的内存管理

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected