[Python-Dev] Extended Buffer Interface/Protocol

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Mar 21 23:32:47 CET 2007

Travis Oliphant wrote:

> The question is should we eliminate the possibility of sharing memory 
> for objects that store data basically as "arrays" of arrays (i.e. true 
> C-style arrays).

Can you clarify what you mean by this? Are you talking
about an array of pointers to other arrays? (This is
not what I would call an "array of arrays", even in C.)

Supporting this kind of thing could be a slippery slope,
since there can be arbitrary levels of complexity to
such a structure. E.g do you support a 1d array of
pointers to 3d arrays of pointers to 2d arrays? Etc.

The more different kinds of format you support, the less
likely it becomes that the thing consuming the data
will be willing to go to the trouble required to
understand it.

> One possible C-API call that Python could grow with the current buffer 
> interface is to allow contiguous-memory mirroring of discontiguous 
> memory,

I don't think the buffer protocol itself should incorporate
anything that requires implicitly copying the data, since
the whole purpose of it is to provide direct access to the
data without need for copying.

It would be okay to supply some utility functions for
re-packing data, though.

> or an iterator object that iterates through every element of any 
> object that exposes the buffer protocol.

Again, for efficiency reasons I wouldn't like to involve
Python objects and iteration mechanisms in this. The
buffer interface is meant to give you raw access to the
data at raw C speeds. Anything else is outside its scope,


More information about the Python-Dev mailing list