mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-04 10:40:19 +00:00
remove object pool from initialize.
This commit is contained in:
parent
01b7eb6073
commit
1127d59b47
@ -18,6 +18,20 @@ namespace pkbind {
|
|||||||
|
|
||||||
class handle;
|
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.
|
/// hold the object long time.
|
||||||
struct object_pool {
|
struct object_pool {
|
||||||
inline static int cache = -1;
|
inline static int cache = -1;
|
||||||
@ -43,6 +57,7 @@ struct object_pool {
|
|||||||
|
|
||||||
/// alloc an object from pool, note that the object is uninitialized.
|
/// alloc an object from pool, note that the object is uninitialized.
|
||||||
static object_ref alloc() {
|
static object_ref alloc() {
|
||||||
|
if(!indices_) { initialize(1024); }
|
||||||
auto& indices = *indices_;
|
auto& indices = *indices_;
|
||||||
if(cache != -1) {
|
if(cache != -1) {
|
||||||
auto index = cache;
|
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>
|
template <typename T>
|
||||||
class lazy {
|
class lazy {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -15,10 +15,6 @@ inline bool initialized = false;
|
|||||||
/// initialize the vm.
|
/// initialize the vm.
|
||||||
inline void initialize(int object_pool_size = 1024) {
|
inline void initialize(int object_pool_size = 1024) {
|
||||||
if(!initialized) { py_initialize(); }
|
if(!initialized) { py_initialize(); }
|
||||||
|
|
||||||
// initialize object pool.
|
|
||||||
object_pool::initialize(object_pool_size);
|
|
||||||
|
|
||||||
action::initialize();
|
action::initialize();
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
@ -27,10 +23,10 @@ inline void initialize(int object_pool_size = 1024) {
|
|||||||
inline void finalize(bool test = false) {
|
inline void finalize(bool test = false) {
|
||||||
if(!initialized) { return; }
|
if(!initialized) { return; }
|
||||||
object_pool::finalize();
|
object_pool::finalize();
|
||||||
if(test) {
|
|
||||||
type::m_type_map.clear();
|
type::m_type_map.clear();
|
||||||
capsule::tp_capsule.reset();
|
capsule::tp_capsule.reset();
|
||||||
cpp_function::tp_function_record.reset();
|
cpp_function::tp_function_record.reset();
|
||||||
|
if(test) {
|
||||||
py_resetvm();
|
py_resetvm();
|
||||||
} else {
|
} else {
|
||||||
py_finalize();
|
py_finalize();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user