[issue27926] ctypes is too slow to convert a Python list to a C array
New submission from Tom Cornebize: It is much faster to construct a Python array from the list and then cast this array, rather than using the "standard" constructor. See attached file to compare the performances. This issue was previously asked on Stackoverflow: http://stackoverflow.com/questions/39225263/why-is-ctypes-so-slow-to-convert-a-python-list-to-a-c-array/ -- components: ctypes files: ctypes_slow.py messages: 274111 nosy: Tom Cornebize priority: normal severity: normal status: open title: ctypes is too slow to convert a Python list to a C array type: performance Added file: http://bugs.python.org/file44320/ctypes_slow.py ___ Python tracker <http://bugs.python.org/issue27926> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27926] ctypes is too slow to convert a Python list to a C array
Tom Cornebize added the comment: Thank you for these explanations. I understand that we get a generic function to the cost of performances. However, I think we should at least tell in the documentation that the constructor (ctypes.c_uint32 * len(t))(*t) is slow and that we can do much faster in some specific cases (e.g. an array of integers). It would be even better to have some specific method(s) to do this in ctypes, instead of having to rely on an array.array just to build a ctypes array from a list. I am not familiar with CPython code, so I do not know if it would be easily feasible. -- ___ Python tracker <http://bugs.python.org/issue27926> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com