I have a python callback function which accepts 2 arguments: a pointer to a chunk of memory, and the length of the memory chunk.
def my_callback( buf, len):
""" buf is of type POINTER(c_ubyte), len is of type c_uint"""
Inside the callback function, i'd like to first convert the memory chunk to ctypes array. I know it can be done by creating a new ctypes array and copy over all the data from the memory chunk.
def my_callback( buf, len):
""" buf is of type POINTER(c_ubyte), len is of type c_uint"""
temp_array = (c_ubyte * len)(*[buf[n] for n in range(len)])
But by this way memory copy is needed. My question is if there is any way to just cast the ctypes pointer to array without memory copying?
Thanks in advance for any answers or hints.