From: Brett on
Hi,

I have created an s-function that works great when I run it, but when I try to run multiple s-functions within the same model I get segmentation faults. I was wondering if there is a problem with the way I am using the PWork vector.

Inside the mdlStart function I create and populate the PWork vector in the following manor:

double *myarray;
myarray = (double *)malloc((numcells)* sizeof(double));
// populate myarray with some values
ssGetPWork(S)[0] = myarray;

Inside mdlOutputs I access the PWork vector like this:

double *myarray;
myarray = ssGetPWorkValue(S,0);

Like I said, this method works great if I am only running 1 s-function, but as soon as I add another instance of it to the model I get Matlab to crash with a segmentation fault. I am using the PWork vector incorrectly?

Thanks
Brett