I am using a third-party C++ library to do some heavy lifting in Julia. On the Julia side, data is stored in an object of type Array{Float64, 2}
(this is roughly similar to a 2D array of doubles). I can pass this to C++ using a pointer to a double
. On the C++ side, however, data is stored in a struct called vector3
:
typedef struct _vector3
{
double x, y, z;
} vector3;
My quick and dirty approach is a five-step process:
- Dynamically allocate an array of structs on the C++ side
- Copy input data from
double*
tovector3*
- Do heavy lifting
- Copy output data from
vector3*
todouble*
- Delete dynamically allocated arrays
Copying large amounts of data is very inefficient. Is there some arcane trickery I can use to avoid copying data from double
to struct
and back? I want to somehow interpret a 1D array of double
(with a size that is a multiple of 3) as a 1D array of a struct with 3 double
members.