Author skrah
Recipients jcon, kermode, mark.dickinson, ncoghlan, petri.lehtinen, pitrou, pv, rupole, skrah, teoliphant
Date 2011-06-27.16:47:35
SpamBayes Score 7.48289e-07
Marked as misclassified No
Message-id <>
In-reply-to <>
Pauli Virtanen <> wrote:
> skrah writes:
> > For example, an exporting object could provide a sliced view by adding 
> > a getslicedbufferproc to PyBufferProcs:
> >
> > int PyObject_GetSlicedBuffer(PyObject *obj, Py_buffer *view, 
> >                              int flags, PyObject *key);
> The same thing can be done via
>     PyObject_GetBuffer(obj, &view, flags);
>     PyBuffer_Slice(&view, &sliced_view, flags, key);
> given an implementation of PyBuffer_Slice. The logic in PyBuffer_Slice does
> not depend on where the buffer comes from, and every buffer can be sliced.

Ok, that sounds good. I came across a comment that base objects can change
their memory layout:

Is that something that must be taken care of?

> >  o The invariant that all allocated memory in the buffer belongs
> >    to the exporting object remains intact.
> Numpy arrays do not have this invariant, and they happily re-export memory
> owned by someone else.

I'm not sure if we use the same terminology. By "exporting object" I meant
the original base object and this is the invariant I wanted:

   m1 = memoryview(base) # directly from base
   m2 = memoryview(m1)   # redirects getbuffer/releasebuffer to base
   m3 = memoryview(m2)   # redirects getbuffer/releasebuffer to base
   s1 = m3[1::2, 1::2]   # redirects getslicedbuffer/releasebuffer to base

That's also what you mean by "re-exporting", right?
Date User Action Args
2011-06-27 16:47:36skrahsetrecipients: + skrah, teoliphant, mark.dickinson, ncoghlan, rupole, kermode, pitrou, pv, jcon, petri.lehtinen
2011-06-27 16:47:35skrahlinkissue10181 messages
2011-06-27 16:47:35skrahcreate