141 template<
typename... Args>
142 GC<T> GetGC(Args&& ...args)
146 if (_listFree.empty())
150 if (_listFree.empty())
152 log(
"PoolArray::GetGC: 失败!");
156 p = _listFree.front();
157 _listFree.pop_front();
158 _listUsed.push_back(p);
161 ret._ref =
new (p) GcRefInfo;
162 ret._ref->_count = 1;
163 ret._p =
new ((GcRefInfo*)p + 1)
T(args...);
174 for (
auto& iter : _listUsed)
177 T* p = (
T*)((GcRefInfo*)iter + 1);
183 for (
auto& iter : _listFree)
190 typeid(
T).name(),
sizeof(GcRefInfo) +
sizeof(
T), _listUsed.size(), _listFree.size());
198 std::list<void*> _listFree;
199 std::list<void*> _listUsed;
201 std::function<void()> _cbDelete;
208 if (_listUsed.size() > 10000)
210 for (
auto iter = _listUsed.begin(); iter != _listUsed.end();)
212 if (((GcRefInfo*)*iter)->_count == 0)
215 T* p = (
T*)((GcRefInfo*)*iter + 1);
218 _listFree.push_back(*iter);
219 _listUsed.erase(iter++);
228 typeid(
T).name(),
sizeof(GcRefInfo) +
sizeof(
T), count);
234 if (count <= _listUsed.size() / 2)
237 size_t num = _listUsed.size() + 10;
238 for (
size_t i = 0; i != num; ++i)
240 void* p = malloc(
sizeof(GcRefInfo) +
sizeof(
T));
246 _listFree.push_back(p);
251 typeid(
T).name(),
sizeof(GcRefInfo) +
sizeof(
T), _listFree.size());