pythoncoder wrote: ↑Wed Mar 30, 2022 9:47 am
Interrupts are soft by default: see
docs.
Each core on the RP2 runs a completely separate instance of MP.
It is possible to disable GC
Code: Select all
>>> import gc
>>> dir(gc)
['__class__', '__name__', 'collect', 'disable', 'enable', 'isenabled', 'mem_alloc', 'mem_free', 'threshold']
>>>
however it requires great care. It is quite difficult to write code which never allocates, as anyone who has written hard ISR's will have discovered.
Hello @pythoncoder
All right!
Is correct to say that, even is difficult do write code which never allocates, if I try to avoid to use objects like as lists/dict/float for example, using array/integer as substitute, when I will run manually the gc.collect(), the GC will run faster? Or independent how much memory needs to be released, the time used for the GC is the same?
Edit:
In my very simple test (just a loop doing gc.collect()), I mean, without lists, dicts or floats, the gc.collect() time is ~1926us (~2ms). Is possible to change something to the gc.collect() be faster?
Below my simple test - gc1.py:
Code: Select all
from machine import freq
import gc, time, array
freq(273_000_000)
gc.disable()
time_list = array.array('i', (0 for _ in range(10)))
count = 0
gc.collect()
while count < 10:
start_time = time.ticks_us()
gc.collect()
end_time = time.ticks_us()
time_list[count] = time.ticks_diff(end_time, start_time)
count += 1
print(time_list)
print(freq())
Output:
Code: Select all
>>> import os
>>> os.uname()
(sysname='rp2', nodename='rp2', release='1.18.0', version='v1.18 on 2022-01-17 (GNU 11.2.0 MinSizeRel)', machine='Raspberry Pi Pico with RP2040')
>>>
>>> import gc1
array('i', [1955, 1926, 1926, 1926, 1926, 1926, 1927, 1926, 1926, 1926])
273000000
>>>
>>>