8000 docs/reference: Mention that slicing a memoryview causes allocation. · micropython/micropython@3720a57 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3720a57

Browse files
peterhinchdpgeorge
authored andcommitted
docs/reference: Mention that slicing a memoryview causes allocation.
1 parent 4954290 commit 3720a57

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/reference/speed_python.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ code these should be pre-allocated and passed as arguments or as bound objects.
9191

9292
When passing slices of objects such as `bytearray` instances, Python creates
9393
a copy which involves allocation of the size proportional to the size of slice.
94-
This can be alleviated using a `memoryview` object. `memoryview` itself
95-
is allocated on heap, but is a small, fixed-size object, regardless of the size
96-
of slice it points too.
94+
This can be alleviated using a `memoryview` object. The `memoryview` itself
95+
is allocated on the heap, but is a small, fixed-size object, regardless of the size
96+
of slice it points too. Slicing a `memoryview` creates a new `memoryview`, so this
97+
cannot be done in an interrupt service routine. Further, the slice syntax ``a:b``
98+
causes further allocation by instantiating a ``slice(a, b)`` object.
9799

98100
.. code:: python
99101

0 commit comments

Comments
 (0)
0