In cython, how do I create an ndarray object with defined properties without allocating memory for its contents?
My problem is that I want to call a function that requires a ndarray but my data is in a pure c array. Due to some restrictions I cannot switch to using an ndarray directly.
Code-segement to illustrate my intention:
cdef:
ndarray[npy_uint64] tmp_buffer
uint64_t * my_buffer
tmp_buffer = np.empty(my_buffer_size, dtype='uint64')
my_buffer = <uint64_t *> malloc(my_buffer_size * sizeof(uint64_t))
(... do something with my_buffer that cannot be done with a ndarray ...)
tmp_buffer.data = my_buffer
some_func(tmp_buffer)
This seems inefficient since for tmp_buffer
memory is allocated and zero-filled which will never be used. How do I avoid this?