i have matlab function compiled c library. using library c# application.
if call function in c library first time, works fine, second call causes exception - mlfmyfunc returns null pointer insted pointer results (output1 , output2 parameters intptr.zero after mlfmyfunc call)
my doublearray
class (wrapper around mx...
functions), tested , think works correctly.
do have idea problem be?
thanks. lukas
c# code:
using native; class matlabalgosbridge { [dllimport("algos.dll"] private static extern bool algosinitialize(); [dllimport("algos.dll")] private static extern void algosterminate(); [dllimport("algos.dll")] private static extern bool mlfmyfunc([in] int nargout, ref intptr output1, ref intptr output2, [in] intptr xvar, [in] intptr time, [in] intptr algoparam, [in] intptr ts, [in] intptr codes); public list<double> analyze(list<double> xvalues) { double[] result = null; try { native.mcl.mclinitializeapplication("null", 0) algosinitialize(); doublearray xvalm = doublearray.creatematrix(xvalues.data.count, 1); // other parameter initialization intptr output1 = intptr.zero; intptr output2 = intptr.zero; mlfmyfunc(2, ref output1, ref output2, xvalm.pointer, time.pointer, params.pointer, ts.pointer, codes.pointer); result = new marray(output1).asdoublevector(); } { algosterminate(); native.mcl.mclterminateapplication(); } return result; } }
solution:
the problem caused repetitionary matlab engine initialization. each time call analyze function engine gets initialized (native.mcl.mclinitializeapplication
] , it's being terminated (native.mcl.mclterminateapplication
) in finally
block, goes wrong repetitionary initialization. built in matlab functions still works properly, library don't.
the solution moving mclinitializeapplication
call outside analyze function , ensuring it's called once in application lifetime.
the problem caused repetitionary matlab engine initialization. each time call analyze
function engine gets initialized (native.mcl.mclinitializeapplication
) , it's being terminated (native.mcl.mclterminateapplication
) in block, goes wrong repetitionary initialization. built in matlab functions still works properly, library don't.
the solution moving mclinitializeapplication
call outside analyze
function , ensuring it's called once in application lifetime.
Comments
Post a Comment