I could not make sense of this discussion nor the sample notebook to adapt to my specific use case.
Any help would be appreciated:
I have a Struct with a fixed size array field. I want to use Julia to build that struct and then call the C code which will do the heavy computation accessing the elements in the struct. The Julia struct does not need to stay in memory after the ccall.
Here is an example:
//C code
typedef struct {
double array[3];
} Mystruct;
int access_struct_array(Mystruct* mystruct)
{
for (int i = 0; i < 3; i++)
{
printf("%f\n", mystruct->array[i]);
}
return 0;
}
Then I use Julia to build the struct and call the C code
type Mystruct
array::Array{Float64, 1}
end
mystruct = Mystruct([1.1, 2.1, 3.1]);
ccall(("access_struct", "./shared.so"), Int, (Ref{Mystruct},), mystruct); #undefined behavior
Why is the behavior of ccall
undefined?
I would say it is related to the fact that Julia arrays are not just pointers. Then, what is the Julia equivalent of a C array?