Alternative to 'clear' or 'clearvars' in standalone C code generation?
Show older comments
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!
Answers (2)
Walter Roberson
on 24 Apr 2013
1 vote
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.
Anthony
on 9 May 2013
0 votes
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!