This commit is contained in:
blueloveTH 2024-01-11 22:36:31 +08:00
parent e1d75a0d85
commit de0db63bca

View File

@ -124,6 +124,8 @@ struct DoubleLinkedList{
template<int __BlockSize=128> template<int __BlockSize=128>
struct MemoryPool{ struct MemoryPool{
static const size_t __MaxBlocks = 256*1024 / __BlockSize; static const size_t __MaxBlocks = 256*1024 / __BlockSize;
static const size_t __MinArenaCount = PK_GC_MIN_THRESHOLD*100 / (256*1024);
struct Block{ struct Block{
void* arena; void* arena;
char data[__BlockSize]; char data[__BlockSize];
@ -224,6 +226,7 @@ struct MemoryPool{
void shrink_to_fit(){ void shrink_to_fit(){
PK_GLOBAL_SCOPE_LOCK(); PK_GLOBAL_SCOPE_LOCK();
if(_arenas.size() < __MinArenaCount) return;
_arenas.apply([this](Arena* arena){ _arenas.apply([this](Arena* arena){
if(arena->full()){ if(arena->full()){
_arenas.erase(arena); _arenas.erase(arena);