[issue40440] allow array.array construction from memoryview w/o copy

Benjamin Keen report at bugs.python.org
Wed May 6 10:32:22 EDT 2020


Benjamin Keen <benjamin.keen at hpe.com> added the comment:

memoryview has a lot of overlap with array, but there are still useful methods (index and count for instance) that memoryview does not have. I don't see a workaround that will run with equivalent speed without writing some extension or adding them to memoryview.

Constructing an array from the memoryview when one wants these isn't a workaround because there may not be enough memory to make a copy. For instance - a memoryview of a mapped disk file that is much larger than the physical memory in the machine.

When writing functions that use an array you don't always know ahead of time whether you are going to be in this situation.  The functions may come from someone else with a bigger machine. This lets the client of the function decide what the right thing to do is as needed without changing the function itself.

So for that reason this brings something that just using the memoryview directly won't provide.  There's value in being able to write things that use the array interface consistently.

You could also think of this as a way of providing compiled-speed index() and count() on certain memoryviews without needing to add new code for that to memoryview itself.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40440>
_______________________________________


More information about the Python-bugs-list mailing list