homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: possible unnecessary memoryview copies?
Type: behavior Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Lluís, r.david.murray, skrah
Priority: normal Keywords:

Created on 2013年11月21日 23:46 by Lluís, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (3)
msg203700 - (view) Author: Lluís (Lluís) Date: 2013年11月21日 23:46
The following code works without raising any AssertionError
 >>> n = "some small integer value"
 >>> m = "some larger integer value"
 >>> assert n<m
 >>> data = bytearray(n)
 >>> mem = memoryview(data)
 >>> assert mem==mem[:]
 >>> assert mem==mem[0:]
 >>> assert mem==mem[:m]
However, the different slices have different IDs, failing on the following asserts:
 >>> assert id(mem)==id(mem[:])
 >>> assert id(mem)==id(mem[0:])
 >>> assert id(mem)==id(mem[:m])
Is the interpreter copying unnecessary data in these type of slices?
msg203717 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013年11月22日 03:11
I believe a new memoryview object is created, but the data is not copied. That's the whole point of memoryview, I think :)
msg203745 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2013年11月22日 12:24
David is correct: No data is copied, but new memoryview objects with different shape and strides are created. That is relatively cheap.
History
Date User Action Args
2022年04月11日 14:57:53adminsetgithub: 63885
2013年11月22日 12:24:43skrahsetstatus: open -> closed

type: enhancement -> behavior

nosy: + skrah
messages: + msg203745
resolution: not a bug
stage: resolved
2013年11月22日 03:11:16r.david.murraysetnosy: + r.david.murray
messages: + msg203717
2013年11月21日 23:46:46Lluíscreate

AltStyle によって変換されたページ (->オリジナル) /