[Python-Dev] Silent Deprecation Candidate -- buffer()
Sat, 29 Jun 2002 12:59:20 -0700 (PDT)
--- Fredrik Lundh <email@example.com> wrote:
> does anyone have any real-life use cases? I've never been
> able to use it for anything, and cannot recall ever seeing it
> being used by anyone else...
As far as I can tell, it only has two uses - To create a (read only)
subview of some other object without making a copy:
a = array.array('b', )*16*1024*1024
b = buffer(a, 512, 1024*1024) # Cheap 1M view of 16M object
Or to add string like qualities to an object which supports the
PyBufferProcs interface, but didn't bother to support a string like
interface. There don't appear to be any of those in the Python core, so
here is a bogus example:
l = lazy.slacker()
b = buffer(l)
x = b[1024:1032]
> (it sure doesn't work for the use cases I thought of when
> first learning about the API...)
I think that's the reason that no one ever fixes its quirks and bugs. As
soon as you understand what it is, you realize that even if it was fixed it
isn't very useful.
What would be useful is a mutable array of bytes that you could optionally
construct from pointer and destructor, that pickled efficiently (no copy to
string), and that reliably retained it's pointer value after letting go of
the GIL (no realloc).
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup