[Python-3000] PEP Draft: Enhancing the buffer protcol

Nick Coghlan ncoghlan at gmail.com
Wed Feb 28 03:19:30 CET 2007

Daniel Stutzbach wrote:
> When an array-like container allocates memory, it allocates a PyArray
> to store the actual data in.  When a caller request a view, the
> container increments the PyArray's reference counter and returns a
> pointer to the PyArray.  The caller is responsible for decrementing
> the reference counter when it is done with the view, so
> bf_releasebuffer becomes unnecessary.
> The container cannot reallocate the memory unless the reference
> counter on the PyArray is exactly 1.
> Basically, I'm wondering if it makes sense to move the new reference
> counter into the buffered memory rather than putting it in the
> container, so that there is only one reference counter implementation.

An object can use a similar approach (by calling Py_INCREF/DECREF in the 
get/release methods), but there is no need for it to be the *only* 
approach (TOOWTDI is given significantly less emphasis in the C API, 
while speed & memory efficiency concerns are higher on the priority list).

> Different question: what is a container supposed to do if a view is
> locking its memory and it needs to reallocate to complete some
> operation?  I assume it would raise an exception, but it would be nice
> to spell this out in the PEP.

I was wondering this, too. I'd also like to know what should happen if 
the object's Python refcount drops to zero, but the view count is still 
greater than 0.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-3000 mailing list