9.4. Compact Memory Pools
PikaPython has a built-in compact memory pool for small resource chips, which is not enabled by default.
Compact memory pooling can reduce memory fragmentation from the usual 20-30% to less than 5%.
Note] Compact memory pooling can slow down the operation speed.
9.4.2. Enabling method
Note that the kernel version must be at least v1.9.0.
220.127.116.11. Enable user configuration
Refer to the configuration document
18.104.22.168. Add configuration items
/* pika_config.h */ #define PIKA_POOL_ENABLE 1 #define PIKA_POOL_SIZE 0x1900
PIKA_POOL_ENABLE means open compact memory pool,
PIKA_POOL_SIZE means the size of the memory pool, the memory pool pre-apply memory from heap, please make sure the heap can apply to that size.
Refer to bsp/stm32g030c8/Booter/pika_config.h
22.214.171.124. Memory pool initialization
Initialize the memory pool before
9.4.3. Freeing the memory pool
If the memory pool needs to be freed, call
9.5. Interrupting a running script
pks_vm_exit() forces the interruption of a running script (also in a dead loop), which can be placed in the interrupt function.
Requires kernel version not lower than
After interrupting a running script, only the VM is exited, the root object can still be used and will not be freed, if you need to free memory, you should execute
obj_deinit()on the root object.