164 template<
typename... Args>
165 GC<T> GetGC(Args&& ...args)
169 if (_listFree.empty())
173 if (_listFree.empty())
175 log(
"PoolArray::GetGC: 失败!");
179 p = _listFree.front();
180 _listFree.pop_front();
181 _listUsed.push_back(p);
184 ret._ref =
new (p) GcRefInfo;
185 ret._ref->_count = 1;
186 ret._p =
new ((GcRefInfo*)p + 1)
T(args...);
197 for (
auto& iter : _listUsed)
200 for (
auto& iter : _listFree)
205 log_easy(fmt::format(
"释放 {}({}byte)内存,(已使用{}+空闲{})个\n",
206 typeid(
T).name(),
sizeof(GcRefInfo) +
sizeof(
T), _listUsed.size(), _listFree.size()));
214 std::list<void*> _listFree;
215 std::list<void*> _listUsed;
217 std::function<void()> _cbDelete;
224 if (_listUsed.size() > 10000)
226 for (
auto iter = _listUsed.begin(); iter != _listUsed.end();)
228 if (((GcRefInfo*)*iter)->_count == 0)
230 _listFree.push_back(*iter);
231 _listUsed.erase(iter++);
241 typeid(
T).name(),
sizeof(GcRefInfo) +
sizeof(
T), count);
247 if (count <= _listUsed.size() / 2)
250 size_t num = _listUsed.size() + 10;
251 for (
size_t i = 0; i != num; ++i)
253 void* p = malloc(
sizeof(GcRefInfo) +
sizeof(
T));
259 _listFree.push_back(p);
265 typeid(
T).name(),
sizeof(GcRefInfo) +
sizeof(
T), _listFree.size());