remove object pool from initialize.

This commit is contained in:
ykiko 2024-09-22 19:50:55 +08:00
parent 01b7eb6073
commit 1127d59b47
2 changed files with 18 additions and 21 deletions

View File

@ -18,6 +18,20 @@ namespace pkbind {
class handle;
struct action {
using function = void (*)();
inline static std::vector<function> starts;
static void initialize() noexcept {
for(auto func: starts) {
func();
}
}
// register a function to be called at the start of the vm.
static void register_start(function func) { starts.push_back(func); }
};
/// hold the object long time.
struct object_pool {
inline static int cache = -1;
@ -43,6 +57,7 @@ struct object_pool {
/// alloc an object from pool, note that the object is uninitialized.
static object_ref alloc() {
if(!indices_) { initialize(1024); }
auto& indices = *indices_;
if(cache != -1) {
auto index = cache;
@ -91,20 +106,6 @@ struct object_pool {
}
};
struct action {
using function = void (*)();
inline static std::vector<function> starts;
static void initialize() noexcept {
for(auto func: starts) {
func();
}
}
// register a function to be called at the start of the vm.
static void register_start(function func) { starts.push_back(func); }
};
template <typename T>
class lazy {
public:

View File

@ -15,10 +15,6 @@ inline bool initialized = false;
/// initialize the vm.
inline void initialize(int object_pool_size = 1024) {
if(!initialized) { py_initialize(); }
// initialize object pool.
object_pool::initialize(object_pool_size);
action::initialize();
initialized = true;
}
@ -27,10 +23,10 @@ inline void initialize(int object_pool_size = 1024) {
inline void finalize(bool test = false) {
if(!initialized) { return; }
object_pool::finalize();
type::m_type_map.clear();
capsule::tp_capsule.reset();
cpp_function::tp_function_record.reset();
if(test) {
type::m_type_map.clear();
capsule::tp_capsule.reset();
cpp_function::tp_function_record.reset();
py_resetvm();
} else {
py_finalize();