|
On Nov 8, 2:56 pm, "Jonathan Currie" <jonathan.cur...@hotmail.com>
wrote:
> I am currently working on a C s function that uses considerable memory (10000+ doubles) for storing intermediate calculations. I am interested in optimizing the memory usage & runtime performance for both simulations and real time workshop code generation.
>
> In my experience, I have three resonable options available:
>
> 1) Create one long Rwork vector, and index the addresses to each of the local variables I use at every function call.
>
> 2) Declare a global pointer, and use malloc to fill this with the required memory during initialization. Then index my variables as above.
>
> 3) Declare multiple global pointers, with multiple calls to malloc for each variable during initialization. This means I do not have to index my variables, but multiple malloc calls is also not suggeted.
>
> If anyone has any suggestions for the best strategy, this would be appreciated!
I'd recommend the first strategy. If you plan on having more than one
instance of this S-Function in your model, and if these intermediate
values need to be different for each instance, the global variable
strategy will fail since global variables are common to all S-Function
instances.
HTH,
Ashish.
|