Greg Ewing wrote:
> Carl Banks wrote:
>
>> Py_BUF_REQUIRE_READONLY - Raise excpetion if the buffer is writable.
>
> Is there a use case for this?

Yes.  The idea is used in NumPy all the time.

Suppose you want to write to an array but only have an algorithm that 
works with contiguous data.  Then you need to make a copy of the data 
into a contiguous buffer but you would like to make the original memory 
read-only until you are done with the algorithm and have copied the data 
back into memory.

That way when you release the GIL, the memory area will now be read-only 
and so other instances won't write to it (because any writes will be 
eradicated by the copy back when the algorithm is done).

NumPy uses this idea all the time in its UPDATE_IF_COPY flag.

-Travis

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to