QUERY · ISSUE
Add .offset()/.seek() method for memoryview for inplace "slicing"
enhancementrfc
Here's an idiom to send a large data buffer thru a short-write stream (e.g., non-blocking socket):
buffer = memoryview(data).cast('b')
while buffer:
try:
nsent = self._socket_send(buffer, flags)
buffer = buffer[nsent:]
The last statement still produces bunch of object garbage. If we could do
buffer.offset(nsent)
it would be cool. Suggestions for better name are welcome.
CANDIDATE · ISSUE
Missing `memoryview.cast` in MicroPython
enhancement
It seems memoryview has no cast() method in MicroPython, has it?
Is there another way to create a memoryview out of an array.array('h', array_size) that results in a bytearray-like memory view without making a copy of the buffer?
In code, for better clarity:
import array
size = 64
a = array.array('h', range(size))
m = memoryview(a).cast('B')
assert len(m) == 2 * size