ssGetPWork doesnt work in callbacks mdlInitializeSizes and mdlInitializeSampleTimes

Hello to everyone,
can somebody tell me why in sfunctions I can not store an object in the callbacks mdlInitializeSizes and mdlInitializeSampleTimes? It works in all the other callback.
the code looks like this
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumPWork(S, 1); // or ssSetNumPWork(S, DYNAMICALLY_SIZED);
.....
ssGetPWork(S)[0] = (void *) new MyClass;
}
Thank you!
G.

回答 (1 件)

Kaustubha Govind
Kaustubha Govind 2011 年 2 月 16 日

0 投票

I don't believe that work vectors are even allocated until after mdlSetWorkWidths - mdlInitializeSizes and mdlInitializeSampleTimes are in the initialization stage of the S-function where attributes of work vectors can be set (like the number of work vectors, their widths, etc.) which can later be used for allocation.
Is there a reason you'd like to initialize your work vectors so early?

2 件のコメント

Giulio
Giulio 2011 年 2 月 16 日
Thanks for your replay.
In my s-function the initialization depends on the parameters in input. In particular the parameters are manipulated by a method of a class. I would be nice instantiate an object of the class and store it once since I will use it in the other callbacks.
Kaustubha Govind
Kaustubha Govind 2011 年 2 月 17 日
In that case, ssSetUserData and ssGetUserData might be more appropriate.

サインインしてコメントする。

製品

質問済み:

2011 年 2 月 16 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by