[Numpy-discussion] Using np.frombuffer and cffi.buffer on array of C structs (problem with struct member padding)
solarjoe at posteo.org
Thu Jan 25 09:51:40 EST 2018
how I could dynamically handle the dtype of a structured array when
an array of C structs with np.frombuffer (regarding the member padding
in the struct).
So far I manually adjusted the dtype of the structured array and added a
field for the padding,
this works on a small scale.
The structs are not defined within my code, but within a third party and
basically I am looking for no-worry hassle free way to handle this,
because there are a lot of structs
Is there some smart way to do this in Numpy?
So far the best approach seems to parse the struct with the cffi
ffi.sizeof(), ffi.offsetof() and maybe ffi.alignof() to find out where
happens and add it dynamically to the dtype. But maybe someone has a
smarter idea how to solve this.
You can find a more detailed description and a working example here:
More information about the NumPy-Discussion