Doing some experiments using python (means python3) for preparing data (also as sending them to wire - SPI) shows it is slow (having limited system). So I was thinking of creation of extension module written in C to defer the critical stuff to. I would like either:
- the
pythonscript would have access to memory block created by themalloc()in the extension module hopefully transparently convertible tobytearray - the extension module would get the pointer to
bytearrayobject created inpythonhopefully transparently convertible tovoid *
The goal is to have zero copy also as zero conversion memory block accessible by both python (as bytearray) and extension module (as void *).
Is there any method, how to achieve this?
OK, it seems to be simpler than expected ;-)
bytearrayprovides direct support for accessing underlying memory block, which is exactly what is neededbytearrayobject from function call argument listC extension module [
test.c]:C extension module build/deployment script [
setup.py]:Build/install the extension module:
Test it: