MCPcopy Create free account
hub / github.com/caozhiyi/CppNet / PoolMalloc

Method PoolMalloc

base/MemoryPool.h:135–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133
134 template<typename T>
135 T* CMemoryPool::PoolMalloc(int sz) {
136 if (sz > __max_bytes) {
137 void* bytes = malloc(sz);
138 memset(bytes, 0, sz);
139 return (T*)bytes;
140 }
141
142 std::unique_lock<std::recursive_mutex> lock(_mutex);
143 MemNode** my_free = &(_free_list[FreeListIndex(sz)]);
144 MemNode* result = *my_free;
145 if (result == nullptr) {
146 void* bytes = ReFill(RoundUp(sz));
147 memset(bytes, 0, sz);
148 return (T*)bytes;
149 }
150
151 *my_free = result->_next;
152 memset(result, 0, sz);
153 return (T*)result;
154 }
155
156 template<typename T>
157 void CMemoryPool::PoolFree(T* &m, int len) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected