[Python-Dev] Allocation of shape and strides fields in Py_buffer

Alexander Belopolsky alexander.belopolsky at gmail.com
Mon Dec 8 22:05:08 CET 2008


I don't have much to add to Nick's reply other than to point you to
numpy, <http://projects.scipy.org/scipy/numpy>, as a reference
implementation.  You may also get better responses on the numpy list,
< numpy-discussion at scipy.org>.

On Mon, Dec 8, 2008 at 3:46 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Antoine Pitrou wrote:
>> For the one-dimensional case, I had in mind a simple scheme where the Py_buffer
>> struct has an additional two-member Py_ssize_t array. Then `shape` and `strides`
>> can point to the first and second member of this array, respectively. This
>> wouldn't solve the multi-dimensional case, however.
>>
>> Thanks for any ideas on how to solve this.
>
> Actually, I think your suggested scheme for the one-dimensional case
> shows the way forward: ownership of the shape and strides memory belongs
> to the object issuing the Py_buffer struct, and that object needs to
> deal with it when the buffer is released. Defining a larger memory chunk
> with the Py_buffer as the first item and the shape and stride info
> tacked onto the end and returning that from PyObject_GetBuffer() means
> that the shape/stride info will be released automatically when the view
> is released via PyBuffer_Release().
>
> For more complicated cases, the object providing the views may need to
> do some internally bookkeeping to map from Py_buffer pointers to
> separately allocated shape/stride information and release those when the
> views are released.
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
> ---------------------------------------------------------------
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/alexander.belopolsky%40gmail.com
>


More information about the Python-Dev mailing list