MATLAB: C++ S-Function DYNAMICALLY_SIZED only known after mdlStart

simulinksimulink c++ s-function sfunction dynamically_sized

Is there a way to set the Input-/Outputports during mdlStart? My Problem is that i am creating an instance of an object during the mdlStart function, and until this point I can't be sure about the size of my output signal.
Of course i could already create a dummy object during mdlInitializeSizes and free the Memory at the end of the function, but this would mean quite an overhead every time this function is called.
Is there any way I could avoid this? The examples from the helpfile did not help me as this example use parameters from simulink, which are already available during the call to mdlInitializeSizes.
Thanks for helping.

Best Answer

Unfortunately, no, the Simulink Engine allocates memory for the input and output signals in time for mdlStart, so the S-function needs to specify the number/size of the inputs and outputs before mdlStart.