2
3
4
5
17
18
19 for (
int i = 0; i < MemoryPool::FREE_LIST_NUM; i++)
21 if (m_FreeLists[i].Size() > 0)
23 ReleaseToCentralCache(m_FreeLists[i], MemoryPool::Bytes(i), m_FreeLists[i].Size());
31
32
33 assert(size <= MemoryPool::MAX_BYTES);
36
37
38 const size_t alignSize = MemoryPool::AlignUp(size);
39 const size_t index = MemoryPool::Index(size);
42
43
44 if (!m_FreeLists[index].Empty())
46 return m_FreeLists[index].Pop();
50
51
54 return FetchFromCentralCache(index, alignSize);
61 assert(size <= MemoryPool::MAX_BYTES);
64
65
66 const size_t index = MemoryPool::Index(size);
67 m_FreeLists[index].Push(obj);
70
71
72 if (m_FreeLists[index].Size() >= m_FreeLists[index].ApplyforNBlocks())
74 ReleaseToCentralCache(m_FreeLists[index], size, m_FreeLists[index].ApplyforNBlocks());
81
82
83 const size_t batchNum = std::min(m_FreeLists[index].ApplyforNBlocks(), MemoryPool::GetNBlocksLimit(alignSize));
85 if (batchNum == m_FreeLists[index].ApplyforNBlocks())
87 m_FreeLists[index].IncreaseInNextApplyFor();
90 void* start =
nullptr;
94
95
96 const size_t actualNum = CentralCache::Get()->FetchRange(start, end, batchNum, alignSize);
98 assert(actualNum >= 1);
101
102
105 m_FreeLists[index].PushRange(MemoryPool::PointerSpace(start), end, actualNum - 1);
113 void* start =
nullptr;
116 list.PopRange(start, end, count);
118 CentralCache::Get()->ReleaseListToSpans(start, size);
122
123
130 objectPool.ThreadDelete(instance);
137
138
139 static _declspec(thread) ThreadCacheThreadWapper pTLSThreadCache;
143 pTLSThreadCache.instance = objectPool.ThreadNew();
ObjectPool Class. Specific situation(Fixed size of block) of MemoryPool.
virtual ~ThreadCacheThreadWapper()
Destructor Function.
ThreadCache * instance
This thread ThreadCache instance.
static ThreadCache *& GetInst()
Get ThreadCache Instance. @reutrn Returns ThreadCache Instance.
Wapper of Instance/Delete ThreadCache in thread.
void Deallocate(void *obj, size_t size)
Recycle object memory.
void * FetchFromCentralCache(size_t index, size_t alignSize)
Fetch memory from central cache if this is run out.
virtual ~ThreadCache()
Destructor Function.
void * Allocate(size_t size)
Allocate memory.
Thread memory cache. First level of memory allocator.
Free list for memory pool.
static ObjectPool< ThreadCache > objectPool
ThreadCache ObjectPool for all threads.