Alloc are very slow. A good speed up would be do define the variable in c_code_support_apply to NULL. You also define another variable for the size of what is allocated.

In c_code, you alloc it or remove/re-alloc if it was too small. But don't free it at the end of the c_code.

What I describe is hacky, but the clean solution is more complicated and not described anywhere.