A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2007-April/072663.html below:

Extended buffer protocol (new version)

[Python-Dev] PEP 3118: Extended buffer protocol (new version) [Python-Dev] PEP 3118: Extended buffer protocol (new version)Travis Oliphant oliphant.travis at ieee.org
Thu Apr 19 06:03:40 CEST 2007
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

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4