zxxc
zxxc

Reputation: 355

What is the best way of allocating array of bytes in Cython and passing it back to Python?

I have a Cython function like cdef generate_data(size) where I'd like to:

I have seen many approaches on the internet but I'm looking for the best/recommended way of doing this in my simple case. I want to:

I'm using Cython 0.20.

Upvotes: 2

Views: 3880

Answers (1)

Veedrac
Veedrac

Reputation: 60147

For allocating memory, I have you covered.

After that, just take a pointer (possibly at the data attribute if you use cpython.array.array like I recommend) and pass that along. You can return the cpython.array.array type and it will become a Python array.

Upvotes: 1

Related Questions