← index #2552Issue #8748
Off-topic · high · value 0.129
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 · ISSUE

Support for buffer protocol in btree module

closedby AmirHmZzopened 2022-06-10updated 2022-06-20
enhancement

Allowing btree module to get binary data as memoryview and bytearray will deduplicate RAM allocation for converting memoryview and bytearray to bytes.

import btree
db = btree.open(open("mydb", "w+b"))
db[memoryview(b"test_key")] = memoryview(b"test_value")

Currently the snippet generates this exception :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert 'memoryview' object to str implicitly

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