Commit 538fa670 authored by Mark Florisson's avatar Mark Florisson

Update memoryview documentation

parent 3b609241
...@@ -185,24 +185,18 @@ contiguous slice (or a strided slice). It can be used like:: ...@@ -185,24 +185,18 @@ contiguous slice (or a strided slice). It can be used like::
my_array = cython.array(shape=(10, 2), itemsize=sizeof(int), format="i") my_array = cython.array(shape=(10, 2), itemsize=sizeof(int), format="i")
cdef int[:, :] my_slice = my_array cdef int[:, :] my_slice = my_array
It also takes an optional argument `mode` ('c' or 'fortran') and a boolean `allocate_buffer`, that indicates It also takes an optional argument `mode` ('c' or 'fortran') and a boolean `allocate_buffer`, that indicates whether a buffer should be allocated and freed when it goes out of scope::
whether a buffer should be allocated::
cdef cython.array my_array = cython.array(..., mode="fortran", allocate_buffer=False) cdef cython.array my_array = cython.array(..., mode="fortran", allocate_buffer=False)
my_array.data = <char *> my_data_pointer my_array.data = <char *> my_data_pointer
# optionally, define a function that can deallocate the data, otherwise # define a function that can deallocate the data (if needed)
# cython.array will call free() on it my_array.callback_free_data = free
cdef void my_callback(char *data):
... free data if necessary
my_array.callback_free_data = my_callback
You can also cast pointers to arrays:: You can also cast pointers to arrays::
cdef cython.array my_array = <int[:10, :2]> my_data_pointer cdef cython.array my_array = <int[:10, :2]> my_data_pointer
Again, when the array will go out of scope, it will free the data, unless you register a callback like above.
Of course, you can also immidiately assign a cython.array to a typed memoryview slice. Of course, you can also immidiately assign a cython.array to a typed memoryview slice.
The arrays are indexable and slicable from Python space just like memoryview objects, and have the same The arrays are indexable and slicable from Python space just like memoryview objects, and have the same
......
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