173 template<
typename... Args>
174 GC<T> GetGC(Args&& ...args)
178 if (_listFree.empty())
182 if (_listFree.empty())
184 log(
"PoolArray::GetGC: 失败!");
188 p = _listFree.back();
189 _listFree.pop_back();
190 _listUsed.push_back(p);
193 ret._p =
new (p)
T(args...);
194 ret._ref =
new ((
unsigned char*)p +
sizeof(
T)) GcRefInfo;
195 ret._ref->_count = 1;
206 for (
auto& iter : _listUsed)
209 for (
auto& iter : _listFree)
214 log_easy(fmt::format(
"释放 {}({}byte)内存,(已使用{}+空闲{})个\n",
215 typeid(
T).name(),
GetNodeSize(), _listUsed.size(), _listFree.size()));
223 std::vector<void*> _listFree;
224 std::list<void*> _listUsed;
226 std::function<void()> _cbDelete;
233 if (_listUsed.size() > 10000)
235 for (
auto iter = _listUsed.begin(); iter != _listUsed.end();)
237 void* p = (
unsigned char*)*iter +
sizeof(
T);
238 if (((GcRefInfo*)p)->_count == 0)
240 _listFree.push_back(*iter);
241 _listUsed.erase(iter++);
257 if (count <= _listUsed.size() / 2)
260 size_t num = _listUsed.size() + 10;
261 for (
size_t i = 0; i != num; ++i)
264 void* p = malloc(MEM_SIZE);
271 _listFree.push_back(p);