Closed
Description
The docs lead one to believe that slicing a memoryview should be allocation free, but this seems not to be the case.
This arose in this forum thread. The user has a timer ISR which uses SPI to read first the number of bytes to read, followed by a subsequent SPI read of the payload. I suggested a memoryview, but this does not work as the slice operation causes an allocation.
I replicated the issue with this sample which can be pasted to a Pyboard:
from machine import SPI
from pyb import Timer
import micropython
import time
micropython.alloc_emergency_exception_buf(100)
s = SPI(1)
buf = bytearray(20)
mv = memoryview(buf)
tim = Timer(1)
def cb(t):
#s.readinto(mv) # Works
s.readinto(mv[:5]) # Memory error
tim.init(freq=10, callback=cb)
while True:
print(buf)
time.sleep(1)
Metadata
Metadata
Assignees
Labels
No labels