Add .offset()/.seek() method for memoryview for inplace "slicing"
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.
Standardizing on an (extension) method to reinitialize an object inplace
It's well-known that a good way to fight memory fragmentation is preallocation and reuse of buffers objects. "And reuse" clause should not be underestimated, because that's the real action which happens there - a preallocated object is reused, using inplace operations. This is easy for objects like buffers, but this idea can be generalized beyond them. One case is being talked at https://github.com/micropython/micropython/issues/2552#issuecomment-262707357 - reusing memoryview with another buffer. But it goes beyond that still. E.g. reusing a closed socket to connect again without allocating a new instance. Reusing uzlib.DecompIO to decompress another stream. Etc.
Related:
https://github.com/micropython/micropython/issues/2622, https://github.com/micropython/micropython/issues/2552, https://github.com/micropython/micropython/issues/2180, https://github.com/micropython/micropython/issues/917
P.S. I understand this has zero chance being implemented in the mainline, I'm going to implement this in my fork. Posting here for wider community review.