I'm working on a C program that needs to repeatedly access a large Matlab data structure. This is a graphics intensive program using OpenGL so it has to be fast.
Repeatedly accessing this data structure with Matlab Engine seems to take too long (~ 10-20 ms for each call to engGetVariable and engPutVariable). I think this is because these functions copy the data in memory.
Thus, instead of using engGetVariable on the data structure itself, now I'm trying to get a pointer to the data structure. If I call engGetVariable on the pointer, I could access the data structure in C by dereferencing the pointer, without having to copy the data in memory first. However I have not been able to get this to work so far. Is something like this possible?
// Make vars in matlab workspace
engEvalString(ep, "a=9");
engEvalString(ep, "ap=getPointer(a)");
// Get variables in C
ap = engGetVariable(ep, "ap");
a = *mxGetPr(ap);
printf("a = %f", a);
ap
variable doing? Why not just get themxArray
corresponding toa
, and callmxGetPr
on that as many times as you like? – Gravida
data structure could be modified in Matlab between times that the engine accesses it. Whena
is modified it appears to be copied to a different memory location, somxGetPr
does not point to the updated copy. – Corneillea
, such asa = -128778304.000000
. – Corneilleprintf("a = %lf", a);
print? – Diaphoresis