This commit is contained in:
blueloveTH 2024-05-03 15:54:29 +08:00
parent d8d5a1588a
commit 48bd3e113e
3 changed files with 21 additions and 13 deletions

View File

@ -4,6 +4,8 @@
namespace pkpy{
void init_memory_pools_if_needed();
void* pool64_alloc(size_t) noexcept;
void pool64_dealloc(void*) noexcept;

View File

@ -267,21 +267,26 @@ struct MemoryPool{
}
};
static MemoryPool<64> pool64;
static MemoryPool<128> pool128;
static MemoryPool<64>* pool64;
static MemoryPool<128>* pool128;
void* pool64_alloc(size_t size) noexcept { return pool64.alloc(size); }
void pool64_dealloc(void* p) noexcept { pool64.dealloc(p); }
void init_memory_pools_if_needed(){
if(pool64 == nullptr) pool64 = new MemoryPool<64>();
if(pool128 == nullptr) pool128 = new MemoryPool<128>();
}
void* pool128_alloc(size_t size) noexcept { return pool128.alloc(size); }
void pool128_dealloc(void* p) noexcept { pool128.dealloc(p); }
void* pool64_alloc(size_t size) noexcept { return pool64->alloc(size); }
void pool64_dealloc(void* p) noexcept { pool64->dealloc(p); }
void* pool128_alloc(size_t size) noexcept { return pool128->alloc(size); }
void pool128_dealloc(void* p) noexcept { pool128->dealloc(p); }
void pools_shrink_to_fit() noexcept {
pool64.shrink_to_fit();
pool128.shrink_to_fit();
pool64->shrink_to_fit();
pool128->shrink_to_fit();
}
std::string pool64_info() noexcept { return pool64.info(); }
std::string pool128_info() noexcept { return pool128.info(); }
std::string pool64_info() noexcept { return pool64->info(); }
std::string pool128_info() noexcept { return pool128->info(); }
}

View File

@ -73,6 +73,7 @@ namespace pkpy{
};
VM::VM(bool enable_os) : heap(this), enable_os(enable_os) {
init_memory_pools_if_needed();
this->vm = this;
this->_c.error = nullptr;
_stdout = [](const char* buf, int size) { std::cout.write(buf, size); };