summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/array/overhead.py
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/tutorial/array/overhead.py')
-rw-r--r--docs/examples/tutorial/array/overhead.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/docs/examples/tutorial/array/overhead.py b/docs/examples/tutorial/array/overhead.py
new file mode 100644
index 000000000..f60c019ce
--- /dev/null
+++ b/docs/examples/tutorial/array/overhead.py
@@ -0,0 +1,17 @@
+from cython.cimports.cpython import array
+import array
+
+a = cython.declare(array.array, array.array('i', [1, 2, 3]))
+ca = cython.declare(cython.int[:], a)
+
+@cython.cfunc
+def overhead(a: cython.object) -> cython.int:
+ ca: cython.int[:] = a
+ return ca[0]
+
+@cython.cfunc
+def no_overhead(ca: cython.int[:]) -> cython.int:
+ 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