[Python-Dev] Re: Deprecate the buffer object?
pf_moore at yahoo.co.uk
Tue Oct 28 18:05:30 EST 2003
Neil Schemenauer <nas-python at python.ca> writes:
> Looks like I was a little quick sending out that message. I found
> more recent postings from Tim and Guido:
> Slippery little beast, that buffer object. :-) I'm going to go
> ahead and add deprecation warnings.
I used it once in combination with ctypes as buffer(a-ctypes-object)
to get at the raw memory whicy ctypes objects expose via the buffer
API. But it was pretty obscure, and I would happily have used an
external module. Like this:
>>> import ctypes
>>> n = ctypes.c_int(12)
<read-only buffer for 0x008F6530, ptr 0x0093FB88, size 4 at 0x00977980>
Basically, the only serious use case is getting the bytes out of
objects which support the buffer API but which *don't* offer a "get
the bytes out" interface.
I've just realised that I could, however, also do this via the array
>>> from array import array
>>> a = array('c')
>>> a.fromstring(n) # Hey - fromstring means "from buffer API"!
There's an extra copy in there. Disaster :-)
Nope, I don't think there's a good use case after all...
This signature intentionally left blank
More information about the Python-Dev