[Python-3000] Using memoryviews

Georg Brandl g.brandl at gmx.net
Sun Nov 23 11:56:29 CET 2008


Josiah Carlson schrieb:
> On Sat, Nov 22, 2008 at 4:18 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> Josiah Carlson <josiah.carlson <at> gmail.com> writes:
>>>
>>> From what I understand of the memoryview when I tried to do the same
>>> thing a few months ago (use memoryview to replace buffer in
>>> asyncore/asynchat), memoryview is incomplete.  It didn't support
>>> character buffer slicing (you know, the 'offset' and 'size' arguments
>>> that were in buffer), and at least a handful of other things (that I
>>> can't remember at the moment).
>>
>> You should try again, memoryview now supports slicing (with the usual Python
>> syntax, e.g. m[2:5]) as well as slice assignment (with the fairly sensible
>> limitation that you can't resize the underlying buffer). There's no real doc for
>> it, but you can look at test_memoryview.py in the Lib/test directory to have a
>> fairly comprehensive list of the things currently supported.
> 
> I meant in the sense of X = memoryview(char_buffer, offset, length).
> Post-facto slicing is nice, but a little more wasteful than necessary.

Why? It's only a view, after all.

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.



More information about the Python-3000 mailing list