MATLAB Answers

Anthony
0

Alternative to 'clear' or 'clearvars' in standalone C code generation?

Asked by Anthony
on 24 Apr 2013
I've searched quite extensively for how to convert a call to clear variables from my matlab code to standalone C (using matlab compiler). Is there an alternative function that can be used?
Thank you!

  0 Comments

Sign in to comment.

2 Answers

Answer by Walter Roberson
on 24 Apr 2013

You cannot clear variables in C.
Variables local to a C function will be released when the function returns. Array variables in C functions cannot be resized.
C does have the ability to create storage (but not variable names) dynamically using malloc(); the storage (but not the variable name) for those can be returned by using free(). This is, though, unlikely to remove that storage from the program: it just returns it to a pool of available storage allocated to the process, to be used next time the process uses malloc().
If you have a need to allocate memory dynamically and have it truly return to the operating system (released by the process) when you are done with it, then you are getting into operating-system behaviour rather than C behaviour. I do not know what operating system mechanisms are preferred for that in MS WIndows.

  0 Comments

Sign in to comment.


Answer by Anthony
on 9 May 2013

Thank you for confirming, Walter.

  0 Comments

Sign in to comment.