cython - Can someone tell me what this c code is doing? -
cansome tell me going in cython code. full code can seen at:
https://github.com/scipy/scipy/blob/master/scipy/spatial/ckdtree.pyx
# standard trick variable-size arrays: # malloc sizeof(nodeinfo)+self.m*sizeof(double) bytes. cdef struct nodeinfo: innernode* node double side_distances[0]
it's old c trick. if don't know how many side_distances
needed, because varies 1 instance of nodeinfo
another, declare array size zero. when allocate memory node, allocate size of struct as defined (sizeof(nodeinfo)
), plus memory number of values want in particular instance (+something * sizeof(double)
). result for instance, have enough memory array of size specified.
it's "trick" in sense uses allocate separate array , store pointer in array. keeping in 1 allocation (attempted) optimization.
iirc, though, zero-sized array allowed c++ standard, not c standard. in c, should define flexible-sized array side_distances[]
, although no doubt many compilers permit c++ version in c extension. either way, though, struct doesn't contain room elements, although correctly aligned double
.
Comments
Post a Comment