I have a Cython function like cdef generate_data(size)
where I'd like to:
- initialise an array of bytes of length
size
- call external (
C
) function to populate the array using array ptr and size - return the array as something understandable by Python (bytearray, bytes, your suggestions)
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:
- avoid memory reallocations
- avoid using numpy
- ideally use something that works in Python 3 and 2.7, although a 2.7 solution is good enough.
I'm using Cython 0.20.