So on https://docs.julialang.org/en/stable/manual/embedding/ it says how to use Julia arrays and the garbage collector in C, but not how to use them together.
Let’s say, I allocated an array in the following manner as it says in the example:
jl_value_t* array_type = jl_apply_array_type((jl_value_t*)jl_float64_type, 1);
jl_array_t* x = jl_alloc_array_1d(array_type, 10);
double *xData = (double*)jl_array_data(x);
If I do not use the array in the next call to any jl_
function, it will be garbage collected, as evidenced by (a) it not giving me a garbage value with jl_gc_enable(0)
and (b) it also working fine if I use the array in Julia in the next call.
I could push the array to the garbage collector, but the example code below is not helping me:
jl_value_t **args;
JL_GC_PUSHARGS(args, 2); // args can now hold 2 `jl_value_t*` objects
args[0] = some_value;
args[1] = some_other_value;
// Do something with args (e.g. call jl_... functions)
JL_GC_POP();
This code requires a jl_value_t**
, but I don’t have such an array. I only have the array_type
, x
and xData
, which are all three of a different type.
So how would I go about pushing the array so that it does not get garbage collected?