2
3
4
5
17 const size_t index = MemoryPool::Index(size);
21 std::unique_lock<std::mutex> lock(m_SpanLists[index].GetMutex());
23 scl::
span* s = GetOneSpan(m_SpanLists[index], size);
30
31
33 while (i < batchNum - 1 && MemoryPool::PointerSpace(end) !=
nullptr)
35 end = MemoryPool::PointerSpace(end);
41 s->m_UseCount += actualNum;
51
52
67
68
69 list.GetMutex().unlock();
72
73
74 size_t k = MemoryPool::GetPages(size);
77
78
79 scl::
span* s = PageCache::Get()->NewSpan(k);
81 s->m_BlockSize = size;
84
85
86 char* start =
reinterpret_cast<
char*>( s->m_PageId << MemoryPool::PAGE_SHIFT );
87 char* end =
reinterpret_cast<
char*>(start + (s->m_NPages << MemoryPool::PAGE_SHIFT));
92
93
99 while (start + size <= end)
102 MemoryPool::PointerSpace(tail) = start;
104 tail = MemoryPool::PointerSpace(tail);
110
111
112 list.GetMutex().lock();
115
116
124 const size_t index = MemoryPool::Index(size);
127 std::unique_lock<std::mutex> lock(m_SpanLists[index].GetMutex());
130
131
137
138
142
143
149
150
151 if (s->m_UseCount == 0)
153 m_SpanLists[index].Erase(s);
157
158
159 m_SpanLists[index].GetMutex().unlock();
162
163
167
168
169 m_SpanLists[index].GetMutex().lock();
size_t FetchRange(void *&start, void *&end, size_t batchNum, size_t size)
Fetch range memory to tc.
static CentralCache m_CentralCache
Single instance of this.
void ReleaseListToSpans(void *start, size_t size)
Release memory to pc.
Central memory cache. Second level of memory allocator.
static void *& PointerSpace(void *obj)
Get object first 4/8 bytes as a pointer.
scl::span * MapObjectToSpan(void *obj) const
Find span by memory pointer.
static PageCache * Get()
Get this single instance.
void ReleaseSpanToPageCache(scl::span *s)
Release span from cc to pc,.
Page memory cache. Third level of memory allocator.
void PushFront(span *s)
Push a span to this list.
span * Begin() const
Get begin pointer.
span * End() const
Get end pointer.
Bidirectional cyclic linked list for span.
void * m_FreeList
current pointer.
bool m_IsUse
True if in use.
Used for manage multiple page memory.