[Python-Dev] buffer objects

Guido van Rossum guido@python.org
Thu, 02 May 2002 08:55:11 -0400


> I recently submitted a (really tiny) patch to allow the buffer() builtin to
> return a read/write PyBufferObject when possible.  Mostly this was just to
> get my feet wet on the patch submission process, but I also think it is the
> correct behavior (am I wrong about this?).  Being new at this, I don't
> know: Am I supposed to find a committer to champion my patch?

If you feel that your patch isn't paid enough attention, please do! :-)

> Also...  Several weeks ago, I brought up the suggestion that arraymodule.c
> arrays should be able to pickle directly and efficiently.  I've since found
> out that the topic of arrays is a complicated one, and now I'm wondering if
> anyone else thinks that buffer objects should pickle.
> 
> I look at buffers as mutable byte-strings.  Having buffers pickle/unpickle
> (without a temporary copy) would avoid most of the questions about data
> types/sizes, endian-ness, ..., while allowing things which built on top of
> buffers (array modules for instance) to pickle efficiently.

Are you referring to the buffer object or the buffer interface?

The buffer interface doesn't define an object type, it defines a
particular way to look at an object (just like the numeric, sequence
and mapping interfaces).  There's no point in prescribing a pickle
format for it.

The buffer object was a mistake.

If you want an efficient way of reading/writing memory buffers, look
at the support for the buffer interface of the file readinto and write
methods.  You already can read and write arrays without copying.

--Guido van Rossum (home page: http://www.python.org/~guido/)