[Numpy-discussion] Altering/initializing NumPy array in C

Bart Baker bartbkr at gmail.com
Thu Jan 2 08:49:11 EST 2014


> You're stack-allocating your array, so the memory is getting recycled for
> other uses as soon as your C function returns. You should malloc it instead
> (but you don't have to worry about free'ing it, numpy will do that when the
> array object is deconstructed). Any C reference will fill you in on the
> details of stack versus malloc allocation.

OK, that makes a lot of sense. I changed them to malloc's of the
appropriate size and now things seems to be working well. It also led to
a good read on stack vs heap.

Thanks a lot,
Bart



More information about the NumPy-Discussion mailing list