3

Is there any difference in Cython between allocating memory like this

from libc.stdlib cimport malloc
cdef int *ar = <int *>malloc(100 * sizeof(int))

and like this

from libc.stdlib cimport malloc
ar = <int *>malloc(100 * sizeof(int))
Konstantin
  • 2,937
  • 10
  • 41
  • 58

1 Answers1

2

No difference. The latter just relies on Cython's ability to deduce the type of ar, which should be pretty easy in this case. If the type deduction fails then you'd get an error message at the cythonizing stage.

DavidW
  • 29,336
  • 6
  • 55
  • 86