Commit 068e3816 authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Moved the second snippet from working with python arrays to the example directory for testing.

parent ff577a2b
from cpython cimport array
import array
cdef array.array a = array.array('i', [1, 2, 3])
cdef int[:] ca = a
cdef int overhead(object a):
cdef int[:] ca = a
return ca[0]
cdef int no_overhead(int[:] ca):
return ca[0]
print(overhead(a)) # new memory view will be constructed, overhead
print(no_overhead(ca)) # ca is already a memory view, so no overhead
...@@ -30,22 +30,10 @@ documentation for the `array module <http://docs.python.org/library/array.html>` ...@@ -30,22 +30,10 @@ documentation for the `array module <http://docs.python.org/library/array.html>`
Notice that when a Python array is assigned to a variable typed as Notice that when a Python array is assigned to a variable typed as
memory view, there will be a slight overhead to construct the memory memory view, there will be a slight overhead to construct the memory
view. However, from that point on the variable can be passed to other view. However, from that point on the variable can be passed to other
functions without overhead, so long as it is typed:: functions without overhead, so long as it is typed:
from cpython cimport array .. literalinclude:: ../../examples/tutorial/array/overhead.pyx
import array
cdef array.array a = array.array('i', [1, 2, 3])
cdef int[:] ca = a
cdef int overhead(object a):
cdef int[:] ca = a
return ca[0]
cdef int no_overhead(int[:] ca):
return ca[0]
print(overhead(a)) # new memory view will be constructed, overhead
print(no_overhead(ca)) # ca is already a memory view, so no overhead
Zero-overhead, unsafe access to raw C pointer Zero-overhead, unsafe access to raw C pointer
--------------------------------------------- ---------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment