Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allocating with malloc in Cython

Tags:

cython

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))
like image 676
Konstantin Avatar asked Oct 20 '25 19:10

Konstantin


1 Answers

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.

like image 180
DavidW Avatar answered Oct 24 '25 01:10

DavidW