I have Matlab code that calls a MEX generated from c++ code. The c++ code requires heavy memory allocation and calculations upon initialization. Using a static pointer, initialization is done only on the first call and the pointer is read from on subsequent calls.
Everything worked just fine until this Matlab code was compiled using Matlab Compiler. Now subsequent calls to the MEX (now happening within matlab compiled code) end up crashing because the static pointer apparently references invalid memory.
What can be done to avoid duplicate initialization in this case?
Thanks, Leo