You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
I'm guessing it's this line that probably gives this impression.
func(mv[30:2000]) # a pointer to memory is passed
I think it's worth updating the docs to clarify that slicing a memoryview creates a new memoryview (as well as requiring a heap allocation for the slice) (ref #4244 for more details).
Not sure what the solution to the underlying issue is as it will likely require extending the memoryview API (e.g. to add a way to adjust an existing memoryview as discussed in #4244 and elsewhere) but this will break CPython compatibility... perhaps we need to raise this with python-dev.
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:
The text was updated successfully, but these errors were encountered: