Convert a Python byte array to C array WARNING ------- DO NOT USE THIS FUNCTION if performance is critical. Instead, use np.array(*) with dtype option to explicitly convert type and then use ndarray.ctypes.data_as(*) to expose underlying buffer as C pointer.
(ctype, values)
| 54 | |
| 55 | |
| 56 | def c_array(ctype, values): |
| 57 | """ |
| 58 | Convert a Python byte array to C array |
| 59 | |
| 60 | WARNING |
| 61 | ------- |
| 62 | DO NOT USE THIS FUNCTION if performance is critical. Instead, use np.array(*) |
| 63 | with dtype option to explicitly convert type and then use |
| 64 | ndarray.ctypes.data_as(*) to expose underlying buffer as C pointer. |
| 65 | """ |
| 66 | return (ctype * len(values))(*values) |
| 67 | |
| 68 | |
| 69 | _T = TypeVar("_T") |
no outgoing calls