← index #2552PR #4150
Related · high · value 0.143
QUERY · ISSUE

Add .offset()/.seek() method for memoryview for inplace "slicing"

openby pfalconopened 2016-10-23updated 2018-12-01
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 · PULL REQUEST

py/objarray: Introduce "memview_offset" alias for "free" field of the…

closedby pfalconopened 2018-09-16updated 2018-12-20

… object.

Both mp_type_array and mp_type_memoryview use the same obejct structure,
mp_obj_array_t, but for the case of memoryview, some fields, e.g. "free",
have different meaning. As the "free" field is also a bitfield, assume
that (anonymous) union can't be uses here, and just a field alieas using
a #define. As it's a define, it should be a selective identifier, so use
verbose "memview_offset" to avoid any clashes.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied