Message139314
Pauli Virtanen <report@bugs.python.org> 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:
http://mail.python.org/pipermail/python-dev/2007-April/072606.html
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:36 | skrah | set | recipients:
+ skrah, teoliphant, mark.dickinson, ncoghlan, rupole, kermode, pitrou, pv, jcon, petri.lehtinen |
2011-06-27 16:47:35 | skrah | link | issue10181 messages |
2011-06-27 16:47:35 | skrah | create | |
|