0

I've seen a cython code with cdef function that uses a temporary array

cdef void some_funct (int* OUT, int size, int const_val) nogil:
    cdef:
        int blah.. blah...blah... 
        float    out_tmp[8]
  
    for i in range(64):
        .....
        ..... out_tmp is involved somehow as intermediate array
        

What is out_tmp ? Is it a vector? a C++ array? a pointer? Do I need to remove/delete or deallocate it before exiting cdef function or cython will do that automatically? If need to manually clean, how to remove/delete/deallocate?

Thank you.

Ong Beng Seong
  • 196
  • 1
  • 11
  • Does this answer your question? [How is the array stored in memory?](https://stackoverflow.com/questions/10696024/how-is-the-array-stored-in-memory) – ead Sep 16 '21 at 06:40
  • Another: https://stackoverflow.com/q/5258724/5769463 – ead Sep 16 '21 at 06:40
  • I'm not completely convinced it's a duplicate (having answered the question I do have a vested interest now though...). Those links are about C and I don't think it's necessarily obvious what C structure Cython is creating – DavidW Sep 16 '21 at 10:34

1 Answers1

3

out_tmp is a stack-allocated C array. It exists only for the duration of the function call (so don't return a pointer to it!) and does not need deallocating.

DavidW
  • 29,336
  • 6
  • 55
  • 86